1. 程式人生 > >easyui combobox 製作帶有複選框的下拉選單

easyui combobox 製作帶有複選框的下拉選單

在實際的專案中,總會遇到下拉框中需要多選的需求。其實使用easyui實現該功能並不難。主要方法是使用combobox中的formatter這個方法。
下面寫個例子。
1.首先設定combobox的multiple屬性為true
2.使用formatter方法來實現顯示的樣子。

$(function(){

 $('#addoper').combobox({
                url:'../css/homepagecss/xx.json',//加入你的本地json檔案。
                panelHeight:200,
                valueField:'id'
, textField:'text', multiple:true,//設定可以多選 formatter:function (row) { var opts = $(this).combobox('options'); return '<input type="checkbox" class="combobox-checkbox">' + row[opts.textField];//關鍵在這一步,在項前面加一個checkbox。opts這個是combobox物件。
} }); })