--- title: CSSRule.cssText slug: Web/API/CSSRule/cssText translation_of: Web/API/CSSRule/cssText --- <div> <div>{{ APIRef("CSSOM") }}</div> </div> <div> </div> <div><span style="font-size: 2.14285714285714rem; font-weight: 700; letter-spacing: -1px; line-height: 30px;">概述</span></div> <p><strong>cssText</strong> 返回样式规则所包含的实际文本.想要能够动态的设置一个样式表规则,查看<a href="/en-US/docs/DOM/Using_dynamic_styling_information" title="DOM/Using_dynamic_styling_information">使用动态样式信息.</a></p> <h2 id="Syntax" name="Syntax">语法</h2> <pre class="syntaxbox"><em>string</em> = cssRule.cssText </pre> <h2 id="Example" name="Example">例子</h2> <pre class="brush:html;"><style> body { background-color: darkblue; } </style> <script> var stylesheet = document.styleSheets[0]; alert(stylesheet.cssRules[0].cssText); // body { background-color: darkblue; } </script> </pre> <h2 id="Specification" name="Specification">规范</h2> <ul> <li><a href="http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSRule">DOM Level 2 Style CSS - Interface CSSStyleRule (introduced in DOM Level 2)</a></li> </ul>