HTML DOM rowIndex 属性

定义和用法

rowIndex 属性返回某一行在表格的行集合中的位置(row index)。

语法

  1. tablerowObject.rowIndex

实例

下面的例子返回了某一行在表格中的位置:

  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function alertRowIndex()
  5. {
  6. alert(document.getElementById("tr1").rowIndex);
  7. }
  8. </script>
  9. </head>
  10. <body>
  11.  
  12. <table border="1">
  13. <tr id="tr1">
  14. <th>Firstname</th>
  15. <th>Lastname</th>
  16. </tr>
  17. <tr id="tr2">
  18. <td>Peter</td>
  19. <td>Griffin</td>
  20. </tr>
  21. </table>
  22. <br />
  23. <input type="button" onclick="alertRowIndex()"
  24. value="Alert row index" />
  25.  
  26. </body>
  27. </html>