Tabela CreateTHead() Metoda
Przykład
Utwórz element <thead> (i wstaw do niego element <tr> i <td>):
// Find a <table> element with id="myTable":
var table = document.getElementById("myTable");
// Create an empty <thead> element and add it to the table:
var header = table.createTHead();
// Create an empty <tr> element and add it to the first position of <thead>:
var row = header.insertRow(0);
// Insert a new cell (<td>) at the first position of the "new" <tr> element:
var cell = row.insertCell(0);
// Add some bold text in the new cell:
cell.innerHTML = "<b>This is a table header</b>";
Definicja i użycie
Metoda createTHead() tworzy pusty element <thead> i dodaje go do tabeli.
Uwaga: Jeśli element <thead> już istnieje w tabeli, metoda createTHead() zwraca istniejący element i nie tworzy nowego.
Uwaga: Element <thead> musi zawierać jeden lub więcej znaczników <tr> wewnątrz.
Wskazówka: Aby usunąć element <thead> z tabeli, użyj metody deleteTHead() .
Obsługa przeglądarki
Method | |||||
---|---|---|---|---|---|
createTHead() | Yes | Yes | Yes | Yes | Yes |
Składnia
tableObject.createTHead()
Parametry
Nic |
Szczegóły techniczne
Wartość zwrotu: | Nowo utworzony (lub istniejący) element <thead> |
---|
Więcej przykładów
Przykład
Utwórz i usuń element <thead>:
function myCreateFunction() {
var table = document.getElementById("myTable");
var header = table.createTHead();
var row = header.insertRow(0);
var cell = row.insertCell(0);
cell.innerHTML = "<b>This is a table header</b>";
}
function myDeleteFunction() {
document.getElementById("myTable").deleteTHead();
}
Powiązane strony
Odniesienie HTML: tag HTML <thead>
❮ Obiekt tabeli