【问题标题】:jQuery and DataTables with not() selector带有 not() 选择器的 jQuery 和 DataTables
【发布时间】:2014-05-12 21:14:02
【问题描述】:

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

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

http://jsfiddle.net/kevmor/7txDz/

【问题讨论】:

  • 谢谢,但现在我意识到我还有另一个问题,我使用每行的复选框作为该行的“全选”复选框。如果我停止冒泡,有没有办法仍然可以全选(复选框)?
  • 选择器'tr:not(input)' 选择所有<tr> 元素,它们也不是<input> 元素。真的,我相信“选择不包括特定后代的 tr”的唯一方法是执行下面的 @DylanHayes 所示的 stopPropagation 方法。我想完全按照你的描述做,这对我有用。

标签: jquery datatables


【解决方案1】:

这称为事件冒泡。

jQuery stopPropagation bubble down

用途:

$('input').on('click', function (e) {
   e.stopPropagation();
})

【讨论】:

    【解决方案2】:

    在输入上使用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 () ...
    

    Demo


    :input 在 jQuery 中选择所有表单元素,包括 复选框、单选框、文本区域、选择等

    【讨论】:

      猜你喜欢
      • 2023-03-28
      • 1970-01-01
      • 2013-09-02
      • 1970-01-01
      • 2012-07-24
      • 1970-01-01
      • 2016-09-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多