我有一个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');
添加主复选框:
<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" >
这适合我。
$(document).on('click', '.ms-selectall', function( event ){
//your code
});
而不是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");
}
});