Home > Web Front-end > JS Tutorial > The difference between document.styleSheets[0].rules and cssRules_javascript skills

The difference between document.styleSheets[0].rules and cssRules_javascript skills

WBOY
Release: 2016-05-16 19:10:11
Original
1939 people have browsed it

I was using Firefox today and suddenly discovered a small problem. The former is used for IE and the latter is used for mozilla browser.


[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute
]

And the counts of rules and cssRules The methods are also different! rules is the selector number; cssRules is the rule number. You can see this by running the following code using IE and firefox respectively.

[Ctrl A select all Note:
If you need to introduce external Js, you need to refresh to execute <script> if(document.styleSheets[0].cssRules){ alert(document.styleSheets[0].cssRules[0].style.cssText) }else{ alert(document.styleSheets[0].rules[0].style.cssText) } </script>]<script> if(document.styleSheets[0].cssRules){ alert(document.styleSheets[0].cssRules[1].selectorText+":"+document.styleSheets[0].cssRules[1].style.cssText) }else{ alert(document.styleSheets[0].rules[1].selectorText+":"+document.styleSheets[0].rules[1].style.cssText) } </script>
Related labels:
and
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template