1) 如何在 HTML 表格中查找行号/索引?生成的表没有任何行 id。
例如:我生成了一个纯 HTML 表格,其中有 10 行, 我正在向此表动态添加行。(在现有行之间)
由于我添加新行,现有的行索引将会更改。现在我需要在添加新行之前找到每行的索引。
最佳答案
"1) How do i find the row number/index in a HTML table? The generated table dosen't have any id for row."
如果您的意思是您已经有一行,并且需要其索引,请不要使用 jQuery 来获取它。表行通过 rowIndex
属性维护自己的索引。
$('table tr').click(function() {
alert( this.rowIndex ); // alert the index number of the clicked row.
});
关于javascript - 用于在 HTML 表中查找行索引的 jQuery 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9096682/