Table createTHead() วิธี
คำนิยามและการใช้งาน
createTHead()
วิธีนี้สร้าง <thead> องค์ประกอบ และเพิ่มมันเข้าสู่ตาราง
หมายเหตุ:ถ้าตารางมี <thead> มีอยู่แล้ว createTHead()
วิธีนี้กลับค่าอิสระโดยไม่ทำการสร้างองค์ประกอบใหม่
หมายเหตุ:ต้องมี <tr> หนึ่งหรือมากกว่าในใน <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 |
สนับสนุน | สนับสนุน | สนับสนุน | สนับสนุน | สนับสนุน |