HTML DOM caption 属性

定义和用法

caption 属性设置或返回表格的 caption 元素。

<caption> 元素定义了一个表格标题。<caption> 标签必须紧跟在 <table> 标签之后,每个表格仅能规定一个 caption。通常,caption 会位于表格之上居中的位置。

语法

  1. tableObject.caption=captionObject

实例

下面的例子可返回表格的 <caption> 元素的文本:

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