Tablo satırları Koleksiyonu
Örnek
Bir tabloda kaç satır olduğunu öğrenin:
var x = document.getElementById("myTable").rows.length;
x'in sonucu şöyle olacaktır:
2
Aşağıda daha fazla "Kendiniz Deneyin" örnekleri.
Tanım ve Kullanım
Satır koleksiyonu, bir tablodaki tüm <tr> öğelerinin bir koleksiyonunu döndürür.
Not: Koleksiyondaki öğeler, kaynak kodda göründükleri gibi sıralanır.
İpucu: Yeni bir satır (<tr>) oluşturmak için insertRow() yöntemini kullanın.
İpucu: Bir satırı kaldırmak için deleteRow() yöntemini kullanın.
İpucu: Yeni bir hücre (<td>) oluşturmak için insertCell() yöntemini kullanın.
İpucu: Bir hücreyi silmek için deleteCell() yöntemini kullanın.
İpucu: Bir tablodaki tüm <td> veya <th> öğelerinin bir koleksiyonunu döndürmek için hücre koleksiyonunu kullanın .
Tarayıcı Desteği
Collection | |||||
---|---|---|---|---|---|
rows | Yes | Yes | Yes | Yes | Yes |
Sözdizimi
tableObject.rows
Özellikler
Property | Description |
---|---|
length | Returns the number of <tr> elements in the collection. Note: This property is read-only |
yöntemler
Method | Description |
---|---|
[index] | Returns the <tr> 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 <tr> 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 <tr> element from the collection with the specified id. Note: Returns null if the id does not exist |
Teknik detaylar
DOM Sürümü: | Çekirdek Düzey 2 Belge Nesnesi |
---|---|
Geri dönüş değeri: | <table> öğesindeki tüm <tr> öğelerini temsil eden bir HTMLCollection Nesnesi. Koleksiyondaki öğeler, kaynak kodda göründükleri gibi sıralanır. |
Daha fazla örnek
Örnek
[ dizin ]
Tablodaki ilk <tr> öğesinin (index 0) innerHTML'sini uyarın:
alert(document.getElementById("myTable").rows[0].innerHTML;
Örnek
öğe ( dizin )
Tablodaki ilk <tr> öğesinin (index 0) innerHTML'sini uyarın:
alert(document.getElementById("myTable").rows.item(0).innerHTML);
Örnek
nameItem( id )
Tabloda id="myRow" ile <tr> öğesinin innerHTML'sini uyarın:
alert(document.getElementById("myTable").rows.namedItem("myRow").innerHTML);
Örnek
İlk tablo hücresinin içeriğini değiştirin:
var x = document.getElementById("myTable").rows[0].cells;
x[0].innerHTML = "NEW CONTENT";
İlgili Sayfalar
HTML referansı: HTML <tr> etiketi
JavaScript referansı: HTML DOM TableRow Nesnesi
❮ Tablo Nesnesi