datatable中全选的Jquery按钮行为。
我正在应用程序中为jquery数据表编写一个selectall按钮。但该按钮的行为不一致,双击该按钮实际上会取消选中datatable中的复选框。这是我的按钮点击事件代码。sampleTable是我的jquery数据表datatable中全选的Jquery按钮行为。,jquery,asp.net,datatables,Jquery,Asp.net,Datatables,我正在应用程序中为jquery数据表编写一个selectall按钮。但该按钮的行为不一致,双击该按钮实际上会取消选中datatable中的复选框。这是我的按钮点击事件代码。sampleTable是我的jquery数据表 $("#button_select_all").click(function () { $(allSamplesTable.fnGetFilteredNodes()).find(':checkbox').each(function () { $this
$("#button_select_all").click(function () {
$(allSamplesTable.fnGetFilteredNodes()).find(':checkbox').each(function () {
$this = $(this);
$this.attr('checked', 'checked');
for (var i = 0; i < _sampleTableExports.length; i++) {
if (_sampleTableExports[i]["Id"] == $(this).val()) {
_sampleTableExports.splice(i, 1);
return true;
}
}
_sampleTableExports.push({ "Name": $(this).attr("name"), "Id": $(this).val() });
});
});
请告知为什么按钮在第二次单击中取消选中复选框 而不是
$this.attr('checked', 'checked');
你能试试吗
$this.prop('checked', true);
如果只希望“全选”按钮触发一次,请尝试以下操作:
$("#button_select_all").one( "click", function() {
// Place your click logic in here
// $(allSamplesTable.fnGetFilteredNodes()).find......
});
但除此之外,您的“全选”按钮似乎正常工作,单击它选择了所有内容,再次单击它将取消选择所有内容 按钮\u选择\u所有元素是按钮还是复选框?我把它作为一个外部按钮。@GBP谢谢。我试过用它。在第二次单击时,它仍然取消选中复选框。每次点击都会打开开关。