<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>