Table createTHead() 메서드
정의와 사용법
createTHead()
메서드는 비어 있는 <thead> 요소 그리고 테이블에 추가합니다。
주의사항:테이블에 <thead> 요소가 이미 존재하면 createTHead()
메서드는 새로운 요소를 생성하지 않고 기존 요소를 반환합니다。
주의사항:thead 요소 내부에는 하나 이상의 <tr> 태그가 있어야 합니다。
안내:thead 요소를 테이블에서 제거하려면 다음을 사용하세요: deleteTHead() 메서드。
다른 참조를 보세요:
HTML 참조 설명서:HTML <thead> 태그
实例
例子 1
创建 <thead> 元素(并在其中插入 <tr> 和 <td> 元素):
// 查找 id="myTable" 的 <table> 元素: var table = document.getElementById("myTable"); // 创建空的 <thead> 元素并将其添加到表中: var header = table.createTHead(); // 创建空的 <tr> 元素并将其添加到 <thead> 的第一个位置: var row = header.insertRow(0); // 在 "新的" <tr> 元素的第一个位置插入一个新单元格 (<td>): var cell = row.insertCell(0); // 在新单元格中添加粗体文本: cell.innerHTML = "<b>This is a table header</b>";
例子 2
创建和删除 <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(); }
문법
tableObject.createTHead()
파라미터
없음。
기술 세부 사항
반환 값: | 새로 만든(또는 기존의)<thead> 요소。 |
---|
브라우저 지원
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
지원 | 지원 | 지원 | 지원 | 지원 |