HTMLStyleElement: sheet 属性
HTMLStyleElement 接口的一个只读的 sheet 属性,包含与该元素关联的样式表。
除非其 type 属性不是 text/css,否则 StyleSheet 始终与 HTMLStyleElement 相关联。
值
一个 StyleSheet 对象,如果与该元素没有关联,则为 null。
示例
假设 <head> 包含以下内容
html
<style id="inline-style">
p {
color: blue;
}
</style>
关联的 HTMLStyleElement 对象的 sheet 属性将返回描述它的 StyleSheet 对象。
js
const style = document.getElementById("inline-style");
console.log(style.sheet.cssRules[0].cssText); // 'p { color: blue; }'
规范
| 规范 |
|---|
| CSS 对象模型 (CSSOM) # dom-linkstyle-sheet |
浏览器兼容性
加载中…