使用jQuery查找表中单击的行
我一直在遵循上的指南,现在我想知道在我的表中单击了哪一行 该表具有以下格式:使用jQuery查找表中单击的行,jquery,function,html-table,click,row,Jquery,Function,Html Table,Click,Row,我一直在遵循上的指南,现在我想知道在我的表中单击了哪一行 该表具有以下格式: Parent --child --child Parent etc. 单击子行时,我想知道单元格中有什么文本(只有文本,而不是html或更多信息)。如何检索该数据 $(function() { $('tr[class^=child-]') .css("cursor","pointer") .attr("title","Click for more info") .click(funct
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)?
});
});
如果我正确理解您的问题,请尝试使用$(this).find('td:first').text()
$(this).text()
要回答标题提出的问题,请查找表中单击的行:
$(document).on('click', 'table tr', function() {
rn = this.rowIndex;
alert('You clicked row: '+rn);
});
或
我有两个专栏$(this).text()给出结果:column1.text+column2.text。我不想要两列的文本。想法?@Dennis你想从哪个专栏获得它?嘿,成功了。非常感谢你!这种语言对我来说太简单了:)
$('table tr').click( function() {
rn = this.rowIndex;
alert('You clicked row: '+rn);
});