我在模态框中使用 jQuery DataTables。其中一列包含复选框。第一次获取选中的复选框值时没有问题。但是,当我关闭模态框并重新选择时,复选框单击事件会触发两次。这是我的代码:
//handle event for checkbox checking.
arresting_officers_table.on("change", ":checkbox", function() {
if($(this).is(':checked')){
console.log('Adding!'); //this log fires twice when clicking only 1 checkbox
//alert('checked! ' + $(this).attr('data-value'));
arresting_officers_ids.push($(this).attr('data-value'));
arresting_officers_names.push($(this).attr('data-name'));
} else {
//remove item
var idx = arresting_officers_ids.indexOf($(this).attr('data-value'));
arresting_officers_ids.splice(idx, 1);
arresting_officers_names.splice(idx, 1);
}
});
非常感谢您的回应。谢谢!