源代码:
下载代码
AI 编程工具
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> </head> <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>
运行结果: