Tabela tBody Collection
Przykład
Dowiedz się, ile elementów <tbody> znajduje się w tabeli:
var x = document.getElementById("myTable").tBodies.length;
Wynikiem x będzie:
2
Więcej przykładów „Wypróbuj sam” poniżej.
Definicja i użycie
Kolekcja tBodies zwraca kolekcję wszystkich elementów <tbody> w tabeli.
Uwaga: elementy w kolekcji są sortowane tak, jak pojawiają się w kodzie źródłowym.
Obsługa przeglądarki
Collection | |||||
---|---|---|---|---|---|
tBodies | Yes | Yes | Yes | Yes | Yes |
Składnia
tableObject.tBodies
Nieruchomości
Property | Description |
---|---|
length | Returns the number of <tbody> elements in the collection. Note: This property is read-only |
Metody
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 |
Szczegóły techniczne
Wersja DOM: | Podstawowy obiekt dokumentu poziomu 2 |
---|---|
Wartość zwrotu: | Obiekt HTMLCollection reprezentujący wszystkie elementy <tbody> w elemencie <table>. Elementy w kolekcji są sortowane tak, jak pojawiają się w kodzie źródłowym |
Więcej przykładów
Przykład
[ indeks ]
Zaalarmuj innerHTML pierwszego elementu <tbody> (indeks 0) w tabeli:
alert(document.getElementById("myTable").tBodies[0].innerHTML;
Przykład
pozycja ( indeks )
Zaalarmuj innerHTML pierwszego elementu <tbody> (indeks 0) w tabeli:
alert(document.getElementById("myTable").tBodies.item(0).innerHTML);
Przykład
nazwany przedmiot ( id )
Zaalarmuj innerHTML elementu <tbody> za pomocą id="myTbody" w tabeli:
alert(document.getElementById("myTable").tBodies.namedItem("myTBody").innerHTML);
Powiązane strony
Odniesienie HTML: tag HTML <tbody>
❮ Obiekt tabeli