CSSRuleList - Web APIs 编辑

A CSSRuleList is an (indirect-modify only) array-like object containing an ordered collection of CSSRule objects.

Description

Each CSSRule can be accessed as rules.item(index), or rules[index], where rules is an object implementing the CSSRuleList interface (such as CSSStylesheet.cssRules), and 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.cssRulesis read-only), 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.

Example

// get the first style sheet’s first rule
var first_rule = document.styleSheets[0].cssRules[0];

See also

CSSRuleList implementations

There are multiple properties in the CSSOM that will return a CSSRuleList. They are:

Specifications

SpecificationStatusComment
CSS Object Model (CSSOM)
The definition of 'CSSRuleList' in that specification.
Working Draft

Browser compatibility

BCD tables only load in the browser

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:53 次

字数:4756

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文