Tabel insertRow() Metode
Voorbeeld
Voeg nuwe ry(s) by die eerste posisie van 'n tabel in (en voeg 'n <td>-element met 'n mate van inhoud daarby in):
// Find a <table> element with id="myTable":
var table = document.getElementById("myTable");
// Create an empty <tr> element and add it to the 1st position of the table:
var row = table.insertRow(0);
// Insert new cells (<td> elements) at the 1st and 2nd position of the "new" <tr> element:
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
// Add some text to the new cells:
cell1.innerHTML = "NEW CELL1";
cell2.innerHTML = "NEW CELL2";
Definisie en gebruik
Die insertRow() metode skep 'n leë <tr> element en voeg dit by 'n tabel.
Die insertRow()-metode voeg die nuwe ry(s) by die gespesifiseerde indeks in die tabel in.
Let wel: 'n <tr> element moet een of meer <th> of <td> elemente bevat.
Wenk: Gebruik die deleteRow() metode om 'n ry te verwyder.
Blaaierondersteuning
Method | |||||
---|---|---|---|---|---|
insertRow() | Yes | Yes | Yes | Yes | Yes |
Sintaksis
tableObject.insertRow(index)
Parameterwaardes
Value | Description |
---|---|
index | Required in Firefox and Opera, optional in IE, Chrome and Safari. A number that specifies the position of the row to insert (starts at 0). The value of 0 results in that the new row will be inserted at the first position. The value of -1 can also be used, this results in a new row being inserted at the last position. This parameter is required in Firefox and Opera, but optional in Internet Explorer, Chrome and Safari.If this parameter is omitted, insertRow() inserts a new row at the last position in Chrome, IE, Firefox and Opera, and at the first position in Safari. |
Tegniese besonderhede
Terugkeerwaarde: | Die ingevoegde <tr> element |
---|
Meer voorbeelde
Voorbeeld
Skep en skrap ry(s):
function myCreateFunction() {
var table = document.getElementById("myTable");
var row = table.insertRow(0);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
cell1.innerHTML = "NEW CELL1";
cell2.innerHTML = "NEW CELL2";
}
function myDeleteFunction() {
document.getElementById("myTable").deleteRow(0);
}
Verwante bladsye
HTML-verwysing: HTML <tr>-merker
❮ Tabelvoorwerp