--- title: CSSStyleRule.selectorText slug: Web/API/CSSStyleRule/selectorText translation_of: Web/API/CSSStyleRule/selectorText ---
{{APIRef("CSSOM") }}

概述

CSSRule.selectorText 属性返回CSS规则的选择符文本,只读。动态设置CSS规则,请看 Using dynamic styling information.

语法

string = cssRule.selectorText

例子

// for cssrule: body { background-color: darkblue; }
var stylesheet = document.styleSheets[0];

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

说明

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

标准