StyleSheetList - Web APIs 编辑
The StyleSheetList
interface represents a list of StyleSheet
.
It is an array-like object but can't be iterated over using Array
methods. However It can be iterated over in a standard for
loop over its indices, or converted to an Array
.
Examples
Get document styleSheet objects with for loop
for (let i = 0; i < document.styleSheets.length; i++) {
let styleSheet = document.styleSheets[i];
}
Get all CSS rules for the document using Array methods
const allCSS = [...document.styleSheets] .map(styleSheet => { try { return [...styleSheet.cssRules] .map(rule => rule.cssText) .join(''); } catch (e) { console.log('Access to stylesheet %s is denied. Ignoring...', styleSheet.href); } }) .filter(Boolean) .join('\n');
Specifications
Specification | Status | Comment |
---|---|---|
CSS Object Model (CSSOM) The definition of 'CSSStyleSheetList' in that specification. | Working Draft |
Browser compatibility
BCD tables only load in the browser
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论