HTML DOM id 属性

定义和用法

idr 属性可设置或返回表格的 id。

语法

  1. tableObject.id=id

实例

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