Table createCaption() 方法

Table 对象参考手册 Table 对象

定义和用法

createCaption() 方法用于在表格中获取或创建 <caption> 元素。

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

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

语法

tableObject.createCaption()


浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要浏览器都支持 createCaption() 方法


实例

实例

下面的例子为表格创建了一个标题:

<html>
<head>
<script>
function displayResult()
{
var x=document.getElementById("myTable").createCaption();
x.innerHTML="<b>My table caption</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()">Create caption</button>

</body>
</html>

尝试一下 »


Table 对象参考手册 Table 对象