Таблица Метод createTHead()
Пример
Создайте элемент <thead> (и вставьте в него элементы <tr> и <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>";
Определение и использование
Метод createTHead() создает пустой элемент <thead> и добавляет его в таблицу.
Примечание. Если элемент <thead> уже существует в таблице, метод createTHead() возвращает существующий, а не создает новый.
Примечание. Внутри элемента <thead> должен быть один или несколько тегов <tr>.
Совет: Чтобы удалить элемент <thead> из таблицы, используйте метод deleteTHead() .
Поддержка браузера
Method | |||||
---|---|---|---|---|---|
createTHead() | Yes | Yes | Yes | Yes | Yes |
Синтаксис
tableObject.createTHead()
Параметры
Никто |
Технические детали
Возвращаемое значение: | Вновь созданный (или существующий) элемент <thead> |
---|
Дополнительные примеры
Пример
Создайте и удалите элемент <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();
}
Связанные страницы
Справочник по HTML: HTML-тег <thead>
❮ Объект таблицы