只读 CSSStyleSheet property ownerRule 返回 CSSImportRule corresponding to the @import at-rule which imported the stylesheet into the document. If the stylesheet wasn't imported into the document using @import , the returned value is null .

句法

var ownerRule = cssStyleSheet.ownerRule;
					

A CSSImportRule corresponding to the @import rule which imported the stylesheet into the document. If the stylesheet wasn't imported into the document using @import , the returned value is null .

范例

This snippet of code looks for rules which were not imported into the document using an @import at-rule.

let ruleList = document.styleSheets[0].cssRules;
for (let rule of ruleList) {
  if (!rule.ownerRule) {
    /* rule is not imported */
  }
}
					

This snipped obtains a reference to the stylesheet associated with the @import and processes it in some manner:

let ruleList = document.styleSheets[0].cssRules;
for (let rule of ruleList) {
  if (rule.ownerRule) {
    checkStylesheet(rule.ownerRule.styleSheet);
  }
}
					

规范

规范 状态 注释
CSS Object Model (CSSOM)
The definition of 'CSSStyleSheet.ownerRule' in that specification.
工作草案

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
ownerRule Chrome Yes Edge 12 Firefox 1 IE 9 Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes

图例

完整支持

完整支持

另请参阅

元数据

  • 最后修改: