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

View in English Always switch to English

CSSStyleRule.selectorText

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月⁩.

概述

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

语法

string = cssRule.selectorText

例子

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

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

说明

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

标准