源代码:
下载代码
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> <style> h1 { color: red; font-size: 50px; } </style> <script> function myFunction() { var s = document.styleSheets[0].rules[0].style; var ruleObj = s.parentRule; document.getElementById("demo").innerHTML = ruleObj.cssText; } </script> </head> <body> <h1>parentRule 属性</h1> <p>parentRule 属性返回 CSSRule 对象,包含 CSS 选择器及声明的样式。 </p> <button onclick="myFunction()">显示 CSS 样式</button> <p id="demo"></p> </body> </html>
运行结果: