StyleSheet: parentStyleSheet 属性

Baseline 已广泛支持

此特性已相当成熟,可在许多设备和浏览器版本上使用。自 ⁨2015 年 7 月⁩以来,各浏览器均已提供此特性。

StyleSheet 接口的 parentStyleSheet 属性返回包含给定样式表的样式表(如果有)。

一个 StyleSheet 对象。

示例

js
// Find the top level stylesheet
const sheet = stylesheet.parentStyleSheet ?? stylesheet;

注意

如果当前样式表是顶级样式表,或者不支持样式表包含,则此属性返回 null

规范

规范
CSS 对象模型 (CSSOM)
# dom-stylesheet-parentstylesheet

浏览器兼容性