Metoda usuwania komórek TableRow ()
Przykład
Usuń pierwszą komórkę (komórki) z wiersza tabeli z id="myRow":
var row = document.getElementById("myRow");
row.deleteCell(0);
Definicja i użycie
Metoda deleteCell() usuwa komórkę w bieżącym wierszu tabeli.
Porada: Użyj metody insertCell() , aby wstawić komórkę w bieżącym wierszu tabeli.
Obsługa przeglądarki
Method | |||||
---|---|---|---|---|---|
deleteCell() | Yes | Yes | Yes | Yes | Yes |
Składnia
tablerowObject.deleteCell(index)
Wartości parametrów
Value | Description |
---|---|
index | Required in Firefox and Opera, optional in IE, Chrome and Safari. An integer (starts at 0) that specifies the position of the cell to delete in the current row. The value of 0 results in that the first cell will be deleted. The value of -1 can also be used; which result in that the last cell will be deleted. If this parameter is omitted, deleteCell() removes the last cell in IE and the first cell in Chrome and Safari. This parameter is required in Firefox and Opera, but optional in Internet Explorer, Chrome and Safari. |
Szczegóły techniczne
Wartość zwrotu: | Brak wartości zwrotu. |
---|
Więcej przykładów
Przykład
Usuń ostatnie komórki z wiersza tabeli z id="myRow":
var row = document.getElementById("myRow");
row.deleteCell(-1);
Przykład
Usuń komórki z pozycji indeksu 1 w wierszu tabeli z id="myRow":
var row = document.getElementById("myRow");
row.deleteCell(1);
Przykład
Usuń komórki na początku pierwszego wiersza tabeli. Kolekcja wierszy tabeli (.rows[0]) zwraca kolekcję wszystkich elementów <tr> w tabeli o identyfikatorze „myTable”. Liczba [0] określa element do pobrania, w tym przykładzie pierwszy wiersz tabeli. Następnie używamy deleteCell(), aby usunąć komórki z pozycji indeksu 0:
var firstRow = document.getElementById("myTable").rows[0];
firstRow.deleteCell(0);
Przykład
Wstaw nowe komórki z zawartością na początku wiersza tabeli z id="myRow":
var row = document.getElementById("myRow");
var x = row.insertCell(0);
x.innerHTML = "New cell";
❮ Obiekt TableRow