关于easyui combobox下拉框实现多选框的实现

function initCombobox(id,url){  
            var value = "";  
            //加载下拉框复选框  
            $('#'+id).combobox({  
                url:url, //后台获取下拉框数据的url  
                method:'post',  
                panelHeight:200,//设置为固定高度,combobox出现竖直滚动条  
                valueField:'Id',  
                textField:'value',  
                multiple:true,  
                formatter: function (row) { //formatter方法就是实现了在每个下拉选项前面增加checkbox框的方法  
                    var opts = $(this).combobox('options');  
                    return '<input type="checkbox" class="combobox-checkbox">' + row[opts.textField]  
                },  
                onLoadSuccess: function () {  //下拉框数据加载成功调用  
                    var opts = $(this).combobox('options');  
                    var target = this;  
                    var values = $(target).combobox('getValues');//获取选中的值的values  
                    $.map(values, function (value) {  
                     
                        var el = opts.finder.getEl(target, value);  
                        el.find('input.combobox-checkbox')._propAttr('checked', true); 
                       
                    })  
                },  
                onSelect: function (row) { //选中一个选项时调用  
                    var opts = $(this).combobox('options');  
                    //获取选中的值的values  
                    $("#"+id).val($(this).combobox('getValues'));  
                     
                   //设置选中值所对应的复选框为选中状态  
                    var el = opts.finder.getEl(this, row[opts.valueField]);  
                    el.find('input.combobox-checkbox')._propAttr('checked', true);  
                },  
                onUnselect: function (row) {//不选中一个选项时调用  
                    var opts = $(this).combobox('options');  
                    //获取选中的值的values  
                    $("#"+id).val($(this).combobox('getValues'));  
                    
                    var el = opts.finder.getEl(this, row[opts.valueField]);  
                    el.find('input.combobox-checkbox')._propAttr('checked', false);  
                }  
            });  

        }  

<script>


$(function(){
initCombobox('IdList','urldata');

});

</script>

     <input id="IdList" name="IdList"  style="width:100%"  class="easyui-combobox" >  


 json.IdList  = (","+$('#IdList').combobox('getValues')+",")   

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值