Latest web development tutorials

HTML DOM Table caption 屬性

Table 對象參考手冊 Table對象

定義和用法

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

caption 元素定義了表格的標題。

注意: <caption>元素定義了一個表格標題。<caption> 標籤必須緊跟在<table> 標籤之後,每個表格僅能規定一個caption。 通常,caption 會位於表格之上居中的位置。

語法

tableObject.caption


瀏覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要瀏覽器都支持caption 屬性


實例

實例

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

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
    alert(document.getElementById("myTable").tBodies.length);
}
</script>
</head>
<body>

<table id="myTable" border="1">
<tbody>
    <tr>
        <td>cell 1</td>
        <td>cell 2</td>
    </tr>
</tbody>
<tbody>
<tr>
        <td>cell 3</td>
        <td>cell 4</td>
</tr>
</tbody>
</table>
<br>
<button type="button" onclick="displayResult()">显示表中 tbody 元素的数目</button>

</body>
</html>

嘗試一下»


Table 對象參考手冊 Table對象