我正在使用Jquery bootstrap multiselect插件,看起来非常好,满足了我所需要的大部分要求.
我想要的唯一附加功能是向OptGroup添加复选框,因此如果用户想要选择完整的组,他们可以通过单击选择全部.
任何帮助赞赏.
http://davidstutz.github.io/bootstrap-multiselect/#examples
尝试这样的事情:
$('.multiselect-group').before('<input type="checkbox" />');
$(document).on('click', '.multiselect-group', function(event) {
var checkAll = true;
var $opts = $(this).parent().nextUntil(':has(.multiselect-group)');
var $inactive = $opts.filter(':not(.active)');
var $toggleMe = $inactive;
if ($inactive.length == 0) {
$toggleMe = $opts;
checkAll = false;
}
$toggleMe.find('input').click();
$(this).parent().find('input').attr('checked', checkAll);
event.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)
无需执行任何代码即可满足您的要求.
enableClickableOptGroups
此插件中有一个选项可以选择所有选项optgroup
http://davidstutz.github.io/bootstrap-multiselect/#configuration-options-enableClickableOptGroups