当前位置:Gxlcms > JavaScript > JS实现为表格动态添加标题的方法

JS实现为表格动态添加标题的方法

时间:2021-07-01 10:21:17 帮助过:3人阅读

本文实例讲述了JS实现为表格动态添加标题的方法。分享给大家供大家参考。具体如下:

JS中的表格对象带有一个createCaption方法用于为表格创建标题caption

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script>
  5. function createCaption()
  6. {
  7. var x=document.getElementById('myTable').createCaption();
  8. x.innerHTML="My table caption";
  9. }
  10. </script>
  11. </head>
  12. <body>
  13. <table id="myTable" border="1">
  14. <tr>
  15. <td>Row1 cell1</td>
  16. <td>Row1 cell2</td>
  17. </tr>
  18. <tr>
  19. <td>Row2 cell1</td>
  20. <td>Row2 cell2</td>
  21. </tr>
  22. </table>
  23. <br>
  24. <input type="button" onclick="createCaption()"
  25. value="Create caption">
  26. </body>
  27. </html>

希望本文所述对大家的javascript程序设计有所帮助。

人气教程排行