aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/cssstylerule/selectortext/index.html
blob: 76a9007cd3f5ce7a9bff21b7d68d0c9f7927bced (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
---
title: CSSStyleRule.selectorText
slug: Web/API/CSSStyleRule/selectorText
translation_of: Web/API/CSSStyleRule/selectorText
---
<div>{{APIRef("CSSOM") }}</div>

<h2 id="Summary" name="Summary">概述</h2>

<p><code><strong>CSSRule.selectorText</strong></code> 属性返回CSS规则的选择符文本,只读。动态设置CSS规则,请看 <a href="/en-US/docs/DOM/Using_dynamic_styling_information" title="/en-US/docs/DOM/Using_dynamic_styling_information">Using dynamic styling information</a>.</p>

<h2 id="Syntax" name="Syntax">语法</h2>

<pre class="syntaxbox"><em>string</em> = cssRule.selectorText
</pre>

<h2 id="Example" name="Example">例子</h2>

<pre class="brush: js">// for cssrule: body { background-color: darkblue; }
var stylesheet = document.styleSheets[0];

alert(stylesheet.cssRules[0].selectorText); // body
</pre>

<h2 class="Notes" id="说明">说明</h2>

<p>浏览器解析选择符的时候可能会剔除不必要的空白字符</p>

<h2 id="Specification" name="Specification">标准</h2>

<ul>
 <li><a href="http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSRule" title="Document Object Model CSS #CSS-CSSRule">Document Object Model CSS - #CSS-CSSRuleCSS</a></li>
</ul>