Javascript 参考手册

HTML DOM 对象

td/th headers 属性

td/th 对象

定义和用法

headers 属性可设置或者返回当前数据单元包含头部信息表头的头部列表。

这个属性的值是引号包括的一列名称,这些名称是用 id 属性定义的不同表头单元格的名称。

语法

设置 headers 属性:

tdObject.headers="header_ids"

or


thObject.headers="header_ids"

返回 headers 属性:

tdObject.headers

or


thObject.headers

提示: headers 属性没有默认值。

描述
header_ids定义以空格为分割符的表头单元id列表

浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要浏览器都支持 headers 属性

实例

实例

显示第二行表头:

<html>

<head>

<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">Name</td>

    <th id="email">Email</td>

    <th id="phone">Phone</td>

    <th id="addr">Address</td>

  </tr>

  <tr>

    <td headers="name">John Doe</td>

    <td headers="email">someone@example.com</td>

    <td headers="phone">+45342323</td>

    <td headers="addr">Rosevn 56,4300 Sandnes,Norway</td>

  </tr>

</table>

<br>


<button type="button" onclick="displayResult()">Get cell headers of second
row</button>


</body>

</html>
尝试一下 »

td/th 对象

新闻动态 联系方式 广告合作 招聘英才 安科实验室 帮助与反馈 About Us

Copyright © 2013 - 2019 Ancii.com All Rights Reserved京ICP备18063983号-5 京公网安备11010802014868号