运行 ❯
获取您
自己
的网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <style> .myStyle { background-color: coral; padding: 16px; } .newStyle { background-color: lightblue; text-align: center; font-size: 25px; padding: 16px; } </style> <body> <h1>The Element Object</h1> <h2>The className Property</h2> <button onclick="myFunction()">Change</button> <p>Click "Change" the change the class attribute of "myDIV" to "newStyle".</p> <div id="myDIV" class="myStyle"> <p>I am myDIV.</p> </div> <script> function myFunction() { document.getElementById("myDIV").className = "newStyle"; } </script> </body> </html>