简单教程
提交运行
代码编辑器:
<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> <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">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()">获取第二行的单元格表头</button>
运行结果: