Bảng tBodies Bộ sưu tập
Thí dụ
Tìm xem có bao nhiêu phần tử <tbody> trong một bảng:
var x = document.getElementById("myTable").tBodies.length;
Kết quả của x sẽ là:
2
Thêm các ví dụ "Hãy tự mình thử" bên dưới.
Định nghĩa và Cách sử dụng
Tập hợp tBodies trả về một tập hợp tất cả các phần tử <tbody> trong một bảng.
Lưu ý: Các phần tử trong bộ sưu tập được sắp xếp như chúng xuất hiện trong mã nguồn.
Hỗ trợ trình duyệt
Collection | |||||
---|---|---|---|---|---|
tBodies | Yes | Yes | Yes | Yes | Yes |
Cú pháp
tableObject.tBodies
Tính chất
Property | Description |
---|---|
length | Returns the number of <tbody> elements in the collection. Note: This property is read-only |
Phương pháp
Method | Description |
---|---|
[index] | Returns the <tbody> element from the collection with the specified index (starts at 0). Note: Returns null if the index number is out of range |
item(index) | Returns the <tbody> element from the collection with the specified index (starts at 0). Note: Returns null if the index number is out of range |
namedItem(id) | Returns the <tbody> element from the collection with the specified id. Note: Returns null if the id does not exist |
Chi tiết kỹ thuật
Phiên bản DOM: | Đối tượng tài liệu cấp 2 cốt lõi |
---|---|
Giá trị trả lại: | Đối tượng HTMLCollection, đại diện cho tất cả các phần tử <tbody> trong phần tử <table>. Các phần tử trong bộ sưu tập được sắp xếp khi chúng xuất hiện trong mã nguồn |
Các ví dụ khác
Thí dụ
[ chỉ mục ]
Cảnh báo InternalHTML của phần tử <tbody> đầu tiên (chỉ mục 0) trong bảng:
alert(document.getElementById("myTable").tBodies[0].innerHTML;
Thí dụ
item ( chỉ mục )
Cảnh báo InternalHTML của phần tử <tbody> đầu tiên (chỉ mục 0) trong bảng:
alert(document.getElementById("myTable").tBodies.item(0).innerHTML);
Thí dụ
NameItem ( id )
Cảnh báo innerHTML của phần tử <tbody> với id = "myTBody" trong bảng:
alert(document.getElementById("myTable").tBodies.namedItem("myTBody").innerHTML);
Các trang liên quan
Tham chiếu HTML: Thẻ HTML <tbody>
❮ Đối tượng bảng