簡體   English   中英

在行點擊但不在超鏈接上的行選擇單擊jquery數據表中的一列?

[英]row selection on row click but not on hyperlink click in one of the column in jquery 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或
點擊單元格?

試試這個,你想看看哪個目標被點擊了,如果它是一個錨標記就忽略它。

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

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

你可以這樣做:

如果顧客是你的餐桌;

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM