cssText 特性为 CSSRule interface returns the actual text of a CSSStyleSheet style-rule.

注意: Do not confuse this property with element-style CSSStyleDeclaration.cssText .

Be aware that this property can no longer be set directly, as it is now specified functionally modify-only, and silently so. In other words, attempting to set it does absolutely nothing , and doesn't even omit a warning or error. Furthermore, it has no settable sub-properties. Therefore, to modify it, use the stylesheet's cssRules [index] properties .selectorText and .style (or its sub-properties). See Using dynamic styling information 了解细节。

句法

string = cssRule.cssText
					

范例

<style>
  body {
    background-color: darkblue;
  }
</style>
<script>
  var stylesheet = document.styleSheets[0];
  alert(stylesheet.cssRules[0].cssText); // body { background-color: darkblue; }
</script>
					

规范

规范 状态 注释
CSS Object Model (CSSOM)
The definition of 'CSSRule: cssText' 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
cssText Chrome 1 Edge 12 Firefox 1 IE ? Opera Yes Safari Yes WebView Android Yes Chrome Android 18 Firefox Android 4 Opera Android Yes Safari iOS Yes Samsung Internet Android 1.0

图例

完整支持

完整支持

兼容性未知 ?

兼容性未知

元数据

  • 最后修改: