Latest web development tutorials

HTML DOM 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>本教程(w3big.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對象