运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h2>How to Access a thead Element</h2> <table> <thead id="myTHead"> <tr> <th>Header 1</th> <th>Header 2</th> </tr> </thead> <tbody> <tr> <td>Cell 1</td> <td>Cell 2</td> </tr> <tr> <td>Cell 3</td> <td>Cell 4</td> </tr> </tbody> </table> <p>Click "Try it" to change the style of the thead element.</p> <button onclick="myFunction()">Try it</button> <script> function myFunction() { const element = document.getElementById("myTHead"); element.style.color = "red"; } </script> </body> </html>