Latest web development tutorials

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