HTML DOM td / th headers attribute
Definition and Usage
headers property sets or returns the current head of the list containing the data unit header information header.
The value of this attribute is a name included in quotation marks, these names with the id attribute is defined in a different table header cell names.
grammar
Setting headers properties:
tdObject.headers="header_ids"
or
thObject.headers="header_ids"
or
thObject.headers="header_ids"
Returns headers attributes:
tdObject.headers
or
thObject.headers
or
thObject.headers
Tip: headers property has no default value.
值 | 描述 |
---|---|
header_ids | 定义以空格为分割符的表头单元id列表 |
Browser Support
All major browsers support headers attribute
Examples
Examples
The second line of the header:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
var table=document.getElementById("myTable");
for (var i=0;i<table.rows[1].cells.length;i++){
alert(table.rows[1].cells[i].headers);
}
}
</script>
</head>
<body>
<table id="myTable" border="1" width="100%">
<tr>
<th id="name">名称</th>
<th id="email">Email</th>
<th id="phone">电话</th>
<th id="addr">地址</th>
</tr>
<tr>
<td headers="name">John Doe</td>
<td headers="email">[email protected]</td>
<td headers="phone">+45342323</td>
<td headers="addr">Rosevn 56,4300 Sandnes,Norway</td>
</tr>
</table>
<br>
<button type="button" onclick="displayResult()">获取第二行的单元格表头</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
var table=document.getElementById("myTable");
for (var i=0;i<table.rows[1].cells.length;i++){
alert(table.rows[1].cells[i].headers);
}
}
</script>
</head>
<body>
<table id="myTable" border="1" width="100%">
<tr>
<th id="name">名称</th>
<th id="email">Email</th>
<th id="phone">电话</th>
<th id="addr">地址</th>
</tr>
<tr>
<td headers="name">John Doe</td>
<td headers="email">[email protected]</td>
<td headers="phone">+45342323</td>
<td headers="addr">Rosevn 56,4300 Sandnes,Norway</td>
</tr>
</table>
<br>
<button type="button" onclick="displayResult()">获取第二行的单元格表头</button>
</body>
</html>
try it"
td / th objects