编辑下面的代码:【加编码】
<html> <body> <h1 id="myH1" style="color:red">我的标题</h1> <p>点击按钮获取 H1 元素的 style 属性。</p> <p id="demo"></p> <button onclick="myFunction()">尝试一下</button> <script> function myFunction() { var x = document.getElementById("myH1").style.color; document.getElementById("demo").innerHTML = x; }; </script> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂