Esempio
Creare un <thead> elemento (and insert a <tr> and <td> element to it) :
// 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>";
Prova tu stesso " Definizione e l'utilizzo
Il createTHead() metodo crea un vuoto <thead> elemento e lo aggiunge alla tabella.
Note: Se un <thead> elemento esiste già sul tavolo, il createTHead() restituisce quello esistente, e non crea una nuova.
Nota: Il <thead> elemento deve avere uno o più <tr> tag all'interno.
Tip: Per rimuovere il <thead> elemento da una tabella, utilizzare il deleteTHead() metodo.
Supporto browser
Metodo | |||||
---|---|---|---|---|---|
createTHead() | sì | sì | sì | sì | sì |
Sintassi
tableObject .createTHead()
parametri
Nessuna |
Dettagli tecnici
Valore di ritorno: | La nuova creazione (or an existing) <thead> elemento |
---|
Altri esempi
Esempio
Creare ed eliminare un <thead> elemento:
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();
}
Prova tu stesso " Pagine correlate
Di riferimento HTML: HTML <thead> tag
<Tabella Object