运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <head> <style> table, th { border: 1px solid black; } </style> </head> <body> <p>Click the button to return the value of the headers attribute of each th element in second row.</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()">Try it</button> <p id="demo"></p> <script> function myFunction() { var table = document.getElementById("myTable"); var txt = ""; var i; for (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>