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

View in English Always switch to English

CSSStyleDeclaration:cssText 属性

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015年7月⁩.

CSSStyleDeclaration 接口的 cssText 属性仅返回或设置元素的内联样式声明文本。

要动态设置样式表规则,参见使用动态样式信息

不要将其与样式表样式规则 CSSRule.cssText 混淆。

包含元素内联样式声明文本的字符串。

示例

html
<span id="s1" style="color: red;">一些文本</span>
js
const elem = document.getElementById("s1");
console.log(elem.style.cssText); // “color: red;”

规范

Specification
CSS Object Model (CSSOM)
# dom-cssstyledeclaration-csstext

浏览器兼容性