Table createCaption() 方法

Table 對象參考手冊 Table 對象

定義和用法

createCaption() 方法用於在表格中獲取或創建 <caption> 元素。

注意:如果 caption 元素在表格中已經存在, createCaption() 方法返回已經存在的標題,而不是新建一個<caption> 元素。

提示: 移除表格的 caption 元素,請使用 deleteCaption() 方法。

語法

tableObject.createCaption()


流覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要流覽器都支持 createCaption() 方法


實例

實例

下麵的例子為表格創建了一個標題:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>IT研修(xuhuhu.com)</title>
<script>
function displayResult(){
    var x=document.getElementById("myTable").createCaption();
    x.innerHTML="<b>我的表格標題</b>";
}
</script>
</head>
<body>

<table id="myTable" border="1">
    <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()">創建一個表格標題</button>

</body>
</html>



Table 對象參考手冊 Table 對象