Table cells 集合

Table 对象参考手册 Table 对象

定义和用法

cells 集合返回表格中所有 <td> 或 <th> 元素。

语法

tableObject.cells

属性

属性描述
length返回集合中 <td> 或 <th> 元素的数目。

方法

方法描述
[name_or_index]一个整数,指定元素检索位置(从0开始)
item(name_or_index)返回集合中的指定索引的元素
namedItem(name)返回集合中指定名称索引的元素索引


浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要浏览器都支持 cells 集合


实例

实例

下面的例子使用 cells 来显示出第一个单元格的内容:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本站教程(icodebang.com)</title>
<script>
function displayResult(){
    alert(document.getElementById("myTable").rows[0].cells.length);
}
</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 对象

0 个评论

要回复文章请先登录注册