<html>
<head>
<style>
table,th
{
border:1px solid black;
}
</style>
</head>
<body>
<p>点击按钮返回第二行中每个 th 元素的 headers 属性的值。</p>
<table id="myTable">
<tr>
<th id="name" colspan="3">Name</th>
</tr>
<tr>
<th headers="fname">First name</th>
<th headers="mname">Middle name</th>
<th headers="lname">Last name</th>
</tr>
</table>
<br>
<button onclick="myFunction()">尝试一下</button>
<p id="demo"></p>
<script>
function myFunction()
{
var table = document.getElementById("myTable");
var txt = "";
for (var i=0; i<table.rows[1].cells.length; i++)
{
txt = txt + table.rows[1].cells[i].headers + "<br>";
}
document.getElementById("demo").innerHTML=txt;
}
</script>
</body>
</html>