Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 单击除第一个td之外的行_Jquery_Datatables - Fatal编程技术网

Jquery 单击除第一个td之外的行

Jquery 单击除第一个td之外的行,jquery,datatables,Jquery,Datatables,我正在尝试单击表行并执行操作。但是,如果他们单击第一个单元格,我不希望该单元格执行该操作 以下是我目前掌握的代码: jQuery('#dyntable tbody tr').live('click', function () { nTr = jQuery(this)[0]; openMessage(oTable, nTr); }); 除了第一个有一个复选框外,这是按预期工作的,因此如果他们在该单元格中单击,我不想调用openMessage(oTable

我正在尝试单击表行并执行操作。但是,如果他们单击第一个
单元格,我不希望该单元格执行该操作

以下是我目前掌握的代码:

jQuery('#dyntable tbody tr').live('click', function () {
        nTr = jQuery(this)[0];

        openMessage(oTable, nTr);
    });
除了第一个
有一个复选框外,这是按预期工作的,因此如果他们在该单元格中单击,我不想调用o
penMessage(oTable,nTr)函数


我还需要
nTr
to=行的内容。

您可以尝试向该
元素添加类或唯一id。然后在处理程序中,针对它进行测试

jQuery('#dyntable tbody tr').live('click', function () {
  var $thisRow = jQuery(this); // cache this selector for performance
  nTr = $thisRow[0];
  if (!$thisRow.hasClass('not_this_one')){
    openMessage(oTable, nTr);
  }
});
这样就可以了:

jQuery('#dyntable tbody tr td:not(:first)').live('click', function () {
        nTr = jQuery(this).parent('tr')[0];

        openMessage("asdf", nTr);
});


function openMessage(oTable, nTr){
  console.log(nTr);
  alert('something happened');    
}


下面是要测试的技巧:

使用行内单击的目标,并检查TD的索引

简化演示:

如果使用jQuery>=1.7转换为on(),则不推荐使用live()。以下假设主表是第页中的永久资产

jQuery('#dyntable').on('click','tbody tr', function (evt) {
    var $cell=$(evt.target).closest('td');
    if( $cell.index()>0){
       openMessage(oTable, this);
   }
});
代码中的这一行是redindant,它只返回与
This

nTr = jQuery(this)[0];
$(文档).ready(函数()
{
$(“#tbluserdata tbody”)。在('click','trtd:not(:first child)'上,函数(){
警报(“写入代码”);
});
});

身份证件
名称
地址
行动
1.
aaa
ccc
删除
1.
aaa
ccc
删除
1.
aaa
ccc
删除

这可能很有用,因为听起来您正在尝试创建标题。为什么不使用
标签呢?我可以让它工作,并将转换为use.on。谢谢??适用于所有行,但每行中的第一个单元格除外
nTr = jQuery(this)[0];
 $("#dyntable tbody").on('click', 'tr td:not(:first-child)',function () {
    alert("success");
});