Table caption 属性

Table 对象参考手册 Table 对象

定义和用法

caption 属性返回了表格的 caption 元素。

caption 元素定义了表格的标题。

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

语法

tableObject.caption


浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要浏览器都支持 caption 属性


实例

实例

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

<html>
<head>
<script>
function displayResult()
{
alert(document.getElementById("myTable").caption.innerHTML);
}
</script>
</head>
<body>

<table id="myTable" border="1">
<caption>This is a table caption</caption>
  <tr>
    <td>cell 1</td>
    <td>cell 2</td>
  </tr>
  <tr>
    <td>cell 3</td>
    <td>cell 4</td>
  </tr>
</table>
<br>
<button type="button" onclick="displayResult()">Alert table caption</button>

</body>
</html>

尝试一下 »


Table 对象参考手册 Table 对象