【发布时间】:2015-04-18 05:00:28
【问题描述】:
我在模态框内使用 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);
}
});
您的回复将不胜感激。谢谢!
【问题讨论】:
标签: javascript jquery checkbox datatables