2011-06-07 45 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); 
}); 
相关问题