在行点击但不在超链接上的行选择单击jquery数据表中的一列?

时间:2012-12-22 05:40:54

标签: javascript html jquery-ui datatable

我的客户dataTable有五列。一列包含超链接。其中一列是复选框。 我想当用户点击该行时,应选择该行(这意味着行颜色应该更改并复选框 应该选择)。我可以使用下面的代码片段来完成它

 $("#customer").on('click', $.fn.getDataTablesClickHandler("#selectAll"));
 //where customer is the html div associated with dataTable and call the same function which gets triggered
 //on call of selectAll html element. Inside that function i toggle the class of row

效果很好。但我的问题是我不希望这一点发生(即行检查)点击其中一列内的链接。 我怎么能这样做?所以基本上我怎么能限制点击单元格中的某些链接点击getDataTablesClickHandler或
点击单元格?

2 个答案:

答案 0 :(得分:2)

尝试这一点,你想要查看被点击的目标,如果是锚标签则忽略它。

$("#customer").on('click', function(event) {
    if(event.target.tagName == 'A')
        return;

    $.fn.getDataTablesClickHandler("#selectAll").apply(this);
});

答案 1 :(得分:1)

你可以这样做:

如果顾客是你的桌子;

 $("#customer").on('click', 'tr', function(){
    if( !$(this).is('tr') )
        return;
    $.fn.getDataTablesClickHandler("#selectAll");
 });