W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <head> <style> table, th, td { border: 1px solid black; margin-top: 20px; } </style> </head> <body> <p>单击该按钮以创建 CAPTION 元素。</p> <button onclick="myFunction()">试一试</button> <table id="myTable"> <tr> <th>Month</th> <th>Savings</th> </tr> <tr> <td>January</td> <td>$100</td> </tr> <tr> <td>February</td> <td>$50</td> </tr> </table> <script> function myFunction() { var x = document.createElement("CAPTION"); var t = document.createTextNode("Monthly savings"); x.appendChild(t); var table = document.getElementById("myTable") table.insertBefore(x, table.childNodes[0]); } </script> </body> </html>