Table rows 集合

Table 对象参考手册 Table 对象

定义和用法

rows 集合返回表格中所有行(TableRow 对象)的一个数组,即一个 HTMLCollection。

该集合包括 <thead>、<tfoot> 和 <tbody> 中定义的所有行。

语法

tableObject.rows

属性

属性 描述
length 返回集合中 <tr> 元素的数目

方法

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

浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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


实例

实例

显示表格中行的数目:

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(json.cn)</title> <script> function displayResult(){ alert(document.getElementById("myTable").rows.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 对象其他扩展