HTML DOM Table tbody collection
Definition and Usage
tBodies collection returns table <tbody> element in the collection.
Note: The elements of the collection to which they appear in the source location to be sorted.
grammar
tableObject.tBodies
Properties
属性 | 描述 |
---|---|
length | 返回集合中 <tbody> 元素的数目。 |
method
方法 | 描述 |
---|---|
[name_or_index] | 一个整数,指定元素检索位置(从0开始) |
item(name_or_index) | 返回集合中的指定索引的元素 |
namedItem(name) | 返回集合中指定名称的元素 |
Browser Support
All major browsers support tBodies collection
Examples
Examples
Displays the number of table tbodies:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
alert(document.getElementById("myTable").tBodies.length);
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tbody>
<tr>
<td>cell 1</td>
<td>cell 2</td>
</tr>
</tbody>
<tbody>
<tr>
<td>cell 3</td>
<td>cell 4</td>
</tr>
</tbody>
</table>
<br>
<button type="button" onclick="displayResult()">显示表中 tbody 元素的数目</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
alert(document.getElementById("myTable").tBodies.length);
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tbody>
<tr>
<td>cell 1</td>
<td>cell 2</td>
</tr>
</tbody>
<tbody>
<tr>
<td>cell 3</td>
<td>cell 4</td>
</tr>
</tbody>
</table>
<br>
<button type="button" onclick="displayResult()">显示表中 tbody 元素的数目</button>
</body>
</html>
try it"
More examples
Align the table row cell contents
Vertical cell content is aligned rows in the table
Align the contents of a single cell
Vertical alignment of cell contents
Table Object