仅当用户启用JavaScript时,才使用一些CSS
为了让我的网页正常降级,我有一些CSS,应该只有在相应的JavaScript函数才能加载。
In order for my webpage to degrade gracefully, I have some CSS that should only be loaded if its corresponding JavaScript will function.
加载的最简单的方法是什么如果且仅当浏览器启用了JavaScript时,本地CSS?
What is the simplest way to load local CSS if and only if the browser has JavaScript enabled?
也是相当大的CSS块,所以我不想写一个JavaScript行每个属性。 (哦,如果需要我可以使用jQuery)。
Also it's quite a big block of CSS, so I'd rather not have to write a JavaScript line to add each attribute. (Oh, and if necessary I can use jQuery).
在noJS的body标签上设置一个类。
Set a class on the body tag of "noJS". Then use Javascript to remove that class.
对于没有JS的情况下使用的CSS规则,只需使用 .noJS。 myRules {}
For the CSS rules that you want to be used when no JS is present, just use .noJS .myRules {}