<html>
<body>
<h1 style="color: red; font-size: 50px;">遍历所有样式属性</h1>
<p>点击按钮可显示 H1 元素的所有样式属性:</p>
<button onclick="myFunction()">试一试</button>
<p id="demo"></p>
<script>
function myFunction() {
var elmnt, i, txt = "";
elmnt = document.getElementsByTagName("h1")[0];
for (i = 0; i < elmnt.style.length; i++) {
txt += elmnt.style.item(i) + "<br>";
}
document.getElementById("demo").innerHTML += txt;
}
</script>
</body>
</html>