2011-06-07 50 views
0

我一直在關注expandable rows上的指南,現在我想知道我的表中點擊了哪行。使用jQuery來查找表中點擊哪一行

表的格式爲:

Parent 
--child 
--child 
Parent 
etc. 

當點擊一個子行,我想知道的是在細胞(只有文字,而不是HTML或瞭解更多信息)是什麼文字。我如何檢索這些數據?

$(function() { 
    $('tr[class^=child-]') 
    .css("cursor","pointer") 
    .attr("title","Click for more info") 
    .click(function(){ 
     //Get row cell text (perhaps use $(this)? 
    }); 
}); 

回答

1

如果我正確理解您的問題,請嘗試簡單使用$(this).find('td:first').text()

+0

我有兩列。 $(this).text()給出結果:column1.text + column2.text。我不希望兩欄中的文字。想法? – 2011-06-07 06:38:59

+0

@丹尼斯你想從哪一列? – alex 2011-06-07 06:40:37

+0

嘿,那工作。非常感謝你!這種語言對我來說太簡單了:) – 2011-06-07 06:43:09

0

要回答你的標題問這個問題,找到該行的表點擊:

$(document).on('click', 'table tr', function() { 
    rn = this.rowIndex; 
    alert('You clicked row: '+rn); 
}); 

OR

$('table tr').click(function() { 
    rn = this.rowIndex; 
    alert('You clicked row: '+rn); 
}); 
相關問題