aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/stylesheetlist
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/stylesheetlist
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/stylesheetlist')
-rw-r--r--files/zh-cn/web/api/stylesheetlist/index.html35
1 files changed, 35 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/stylesheetlist/index.html b/files/zh-cn/web/api/stylesheetlist/index.html
new file mode 100644
index 0000000000..88d098c111
--- /dev/null
+++ b/files/zh-cn/web/api/stylesheetlist/index.html
@@ -0,0 +1,35 @@
+---
+title: StyleSheetList
+slug: Web/API/StyleSheetList
+translation_of: Web/API/StyleSheetList
+---
+<p>{{APIRef("CSSOM")}}</p>
+
+<p>StyleSheetLists 接口表示一个StyleSheet的列表。</p>
+
+<p>这是一个像数组一样的对象,但是不能使用数组方法进行遍历。但是它可以通过for循环遍历其下标,或者把它转换成数组。</p>
+
+<h2 id="Example" name="Example">范例</h2>
+
+<h3 id="使用for循环获取文档_styleSheet_对象">使用for循环获取文档 <a href="https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet">styleSheet</a> 对象</h3>
+
+<pre><code>for (var i=0; i &lt; document.styleSheets.length; i++){
+ var styleSheet = document.styleSheets[i];
+}</code></pre>
+
+<h3 id="使用Array方法获取文档的所有CSS规则">使用Array方法获取文档的所有CSS规则</h3>
+
+<pre><code>var allCSS =
+ [].slice.call(document.styleSheets)
+ .reduce(function (prev, styleSheet) {
+ if (styleSheet.cssRules) {
+ return prev +
+ [].slice.call(styleSheet.cssRules)
+ .reduce(function (prev, cssRule) {
+ return prev + cssRule.cssText;
+ }, '');
+ } else {
+ return prev;
+ }
+ }, '');</code>
+</pre>