HTMLTableElement: createTHead() 方法

Baseline 已广泛支持

此特性已相当成熟,可在许多设备和浏览器版本上使用。自 ⁨2015 年 7 月⁩以来,各浏览器均已提供此特性。

HTMLTableElement 对象的 createTHead() 方法会返回与给定 <table> 元素关联的 <thead> 元素。如果表格中不存在表头,此方法会创建表头,然后返回它。

注意: 如果不存在表头,createTHead() 会直接将新的表头插入表格中。与使用 Document.createElement() 创建新的 <thead> 元素不同,这里不需要单独添加表头。

语法

js
createTHead()

参数

无。

返回值

HTMLTableSectionElement

示例

js
let myHead = myTable.createTHead();
// Now this should be true: myHead === myTable.tHead

规范

规范
HTML
# dom-table-createthead-dev

浏览器兼容性