Return 页面加载时行的 rowIndex
Return row's rowIndex on page load
我正在尝试打印 table 中每一行的 rowIndex。我希望将它放在 table 本身内,但我似乎无法让它工作:
<table>
<tr>
<td>r1.cell1</td>
<td>r1.cell2</td>
<td><script>document.write("rowindex = " + this.parentNode.rowIndex);</script></td>
</tr>
<tr>
<td>r2.cell1</td>
<td>r2.cell2</td>
<td><script>document.write("rowindex = " + this.parentNode.rowIndex);</script></td>
</tr>
</table>
使用jQuery 是在文档加载后进行的简单事情。假设这是整个页面中唯一的 table 你可以做类似
$('td:last-child').each(function(index, item) { $(item).html(index)})
您可以使用这个 JSFiddle 查看它的实际效果 http://jsfiddle.net/qurm4304/
我正在尝试打印 table 中每一行的 rowIndex。我希望将它放在 table 本身内,但我似乎无法让它工作:
<table>
<tr>
<td>r1.cell1</td>
<td>r1.cell2</td>
<td><script>document.write("rowindex = " + this.parentNode.rowIndex);</script></td>
</tr>
<tr>
<td>r2.cell1</td>
<td>r2.cell2</td>
<td><script>document.write("rowindex = " + this.parentNode.rowIndex);</script></td>
</tr>
</table>
使用jQuery 是在文档加载后进行的简单事情。假设这是整个页面中唯一的 table 你可以做类似
$('td:last-child').each(function(index, item) { $(item).html(index)})
您可以使用这个 JSFiddle 查看它的实际效果 http://jsfiddle.net/qurm4304/