此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

StyleSheet:parentStyleSheet 属性

基线 广泛可用

自 2015年7月 起,此特性已在主流浏览器中得到支持,可在大多数设备和浏览器版本中正常使用。

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

一个 StyleSheet 对象。

示例

js
// 查找顶级样式表
const sheet = stylesheet.parentStyleSheet ?? stylesheet;

备注

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

规范

规范
CSS Object Model (CSSOM)
# dom-stylesheet-parentstylesheet

浏览器兼容性