jQuery Multiselect - 选择所有事件处理程序

问题描述 投票:1回答:3

我有一个jQuery multiselect,默认选中所有选项。每当所选选项发生变化时,我都会相应地重新加载页面数据。

一切都很好,除了“全选”按钮单击不会触发onChange事件,并且单击时无法重新加载数据。我尝试将事件处理程序附加到checkAll并选择AllAll但是无济于事。

$("#testselect").multiselect({
        nonSelectedText: 'None',
        allSelectedText: 'All Selected',
        includeSelectAllOption: true,
        buttonWidth: '100%',
        checkAll: function () {
            alert("check all"); // Doesn't work
        },
        selectAll: function () {
            alert("select all"); // Doesn't work
        },
        onChange: function (option, checked, select) {
            alert("onchange") // Works but not for 'All Selected'
            // Do something
        }
});
$("#testselect").multiselect('selectAll', false);
$("#testselect").multiselect('updateButtonText');
javascript jquery multi-select jquery-multiselect
3个回答
0
投票

添加主复选框:

<th>SELECT ALL<br/><input type="checkbox"  onClick="toggle(this)" /></th>

添加脚本:

          <script>

          function toggle(source) {
           checkboxes = document.getElementsByName('checkbox[]');
           if(x=1)
           {
             for(var i=0, n=checkboxes.length;i<n;i++) {
               checkboxes[i].checked = source.checked;
             }}}



           </script>

添加复选框您想按主要选择:

<input name="checkbox[]"    type="checkbox" >

0
投票

这适合我。

$(document).on('click', '.ms-selectall', function( event ){
        //your code
});

0
投票

而不是checkAll和selectAll,使用onSelectAll和onDeselectAll事件

示例:

$("#testselect").multiselect({
        nonSelectedText: 'None',
        allSelectedText: 'All Selected',
        includeSelectAllOption: true,
        buttonWidth: '100%',
        onChange: function (option, checked, select) {
            alert("onchange") // Works but not for 'All Selected'
        },
        onSelectAll: function () {
            console.log("call when select all");
        },
        onDeselectAll: function () {
            console.log("call when deselect all");
        }
});
© www.soinside.com 2019 - 2024. All rights reserved.