源代码:
下载代码
AI 编程工具
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> </head> <body> <h1 style="color: red; font-size: 50px; ">循环输出所有 CSS 属性</h1> <p>点击按钮显示所有 h1 元素的 CSS 属性。</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>
运行结果: