带有not()选择器的jQuery和DataTables

带有not()选择器的jQuery和DataTables,jquery,datatables,Jquery,Datatables,在下面的代码中,如何使单击复选框或输入字段不会切换行选择?我尝试使用not()选择器,如中所示: $('#example tbody').on('click', 'tr:not(input)', function () ... 在输入端使用e.stopPropagation(): $('#example tbody').on('click', ':input', function(e){ e.stopPropagation(); // stops the event to bubble

在下面的代码中,如何使单击复选框或输入字段不会切换行选择?我尝试使用not()选择器,如中所示:

$('#example tbody').on('click', 'tr:not(input)', function () ...

在输入端使用
e.stopPropagation()

$('#example tbody').on('click', ':input', function(e){
   e.stopPropagation(); // stops the event to bubble up to the dom tree
}).on('click', 'tr', function () ...


:jQuery中的input
选择所有表单元素,包括复选框、收音机、文本区域、selects等

这称为事件冒泡

使用:


谢谢,这很有效,但现在我意识到我还有另一个问题,我正在使用每行的复选框作为该行的“全选”复选框。如果我停止冒泡,还有什么方法可以执行全选(复选框)?选择器
'tr:not(input)
选择所有也不是
元素的
元素。事实上,“选择一个tr排除特定后代”的唯一方法是,我相信@DylanHayes的stopPropagation方法如下所示。我想做的正是你所描述的,这对我很有效。
$('input').on('click', function (e) {
   e.stopPropagation();
})