编辑下面的代码:【加编码】
<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 </th><th id="email">Email </th><th id="phone">Phone </th><th id="addr">Address </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()">Get cell headers of second row</button> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂