TableHeader headers attribute

Definition and Usage

headers Set or return the value of the headers attribute.

<th> headers attribute Specify a list of header cells that contain the title information of the current data cell.

See also:

HTML 参考手册:HTML <th> 标签

Example

Example 1

Return the headers attribute value of the <th> element with id "myTh":

var x = document.getElementById("myTh").headers;

Try it yourself

Example 2

Display the cell titles of the second row:

var table = document.getElementById("myTable");
var txt = "";
var i;
for (i = 0; i < table.rows[1].cells.length; i++) {
  txt = txt + table.rows[1].cells[i].headers + "<br>";
}

Try it yourself

Example 3

Change the headers attribute value of the <th> element with id "myTh":

document.getElementById("myTh").headers = "newValue";

Try it yourself

Syntax

Return headers attribute:

tableheaderObject.headers

Set headers attribute:

tableheaderObject.headers == header_ids

属性值

描述
header_ids 规定与表格单元格相关的一个或多个标题单元格的 id 列表,以空格分隔。

技术细节

返回值: 字符串值,包含以空格分隔的标题单元格标识符列表。

浏览器支持

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
支持 支持 支持 支持 支持

相关页面

HTML 参考手册:HTML <th> headers 属性