A
CSSRuleList
is an (indirect-modify only) array-like object containing an ordered collection of
CSSRule
对象。
每个
CSSRule
can be accessed as
rules
.item(
index
),
or simply
rules
[
index
]
,其中
rules
是对象实现
CSSRuleList
interface (such as
CSSStylesheet
.cssRules
),和
index
is the 0-based index of the rule, in the order as it appears in the style sheet CSS. The number of rules in the list is
rules
.length
.
Note that being
indirect-modify
(
changeable
but
only having
read-methods), rules are
NOT
added or removed from the list directly, but instead here, only via its parent stylesheet. In fact,
.insertRule()
and
.deleteRule()
are not even methods of CSSRuleList, but only of
CSSStyleSheet
. If however, for some reason the list does need to be modified but has no parent stylesheet (perhaps being a
livecopy
of a list that does), it cannot just be assigned one (as it has
no such property
), and neither can it be assigned to one (as stylesheet.css
Rules
is
只读
), but it must unfortunately be
inserted
into one, rule by rule, and unless combining lists, after any existing list therein is deleted, rule by rule.
// get the first style sheet’s first rule var first_rule = document.styleSheets[0].cssRules[0];
There are multiple properties in the CSSOM that will return a
CSSRuleList
. They are:
CSSStyleSheet
property
cssRules
CSSMediaRule
property
cssRules
CSSKeyframesRule
property
cssRules
CSSMozDocumentRule
property
cssRules
| 规范 | 状态 | 注释 |
|---|---|---|
|
CSS Object Model (CSSOM)
The definition of 'CSSRuleList' in that specification. |
工作草案 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
CSSRuleList
|
Chrome 1 | Edge ≤18 | Firefox 1 | IE ? | Opera Yes | Safari Yes | WebView Android Yes | Chrome Android Yes | Firefox Android 4 | Opera Android Yes | Safari iOS Yes | Samsung Internet Android Yes |
item
|
Chrome 1 | Edge 12 | Firefox 1 | IE ? | Opera Yes | Safari Yes | WebView Android Yes | Chrome Android Yes | Firefox Android 4 | Opera Android Yes | Safari iOS Yes | Samsung Internet Android Yes |
length
|
Chrome 1 | Edge 12 | Firefox 25 | IE ? | Opera Yes | Safari Yes | WebView Android Yes | Chrome Android Yes | Firefox Android 25 | Opera Android Yes | Safari iOS Yes | Samsung Internet Android Yes |
完整支持
兼容性未知
CSSRuleList
AnimationEvent
CSS
CSSConditionRule
CSSGroupingRule
CSSKeyframeRule
CSSKeyframesRule
CSSMediaRule
CSSNamespaceRule
CSSPageRule
CSSRule
CSSStyleDeclaration
CSSStyleRule
CSSStyleSheet
CSSSupportsRule
CaretPosition
LinkStyle
MediaQueryList
MediaQueryListListener
Screen
StyleSheet
StyleSheetList
TransitionEvent