easyui combobox 制作带有复选框的下拉菜单

版权声明:本文为博主原创文章,转载需注明来源 https://blog.csdn.net/fsxxzq521/article/details/78693218

在实际的项目中,总会遇到下拉框中需要多选的需求。其实使用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对象。

                }

            });
            })

猜你喜欢

转载自blog.csdn.net/fsxxzq521/article/details/78693218