简体   繁体   English

禁用JavaScript时的Css后备

[英]Css fallback when JavaScript is disabled

With jQuery Mobile, I use this snippet to call libaries... 使用jQuery Mobile,我使用这个片段来调用libaries ...

<script src="//code.jquery.com/jquery-1.6.4.min.js"></script>
<script>
if(typeof jQuery === 'undefined') 
{
    document.write(unescape('%3Cscript src="js/jquery-1.6.4.min.js"%3E%3C/script%3E'));
    document.write(unescape('%3Cscript src="jqm/jquery.mobile-1.1.0.min.js"%3E%3C/script%3E'));     
    document.write(unescape('%3Clink rel="stylesheet" href="jqm/jquery.mobile-1.1.0.min.css"%3E%3C/script%3E'));
    document.write(unescape('%3Clink rel="stylesheet" href="jqm/jquery.mobile.structure-1.1.0.min.css"%3E%3C/script%3E'));
}
else
{
    document.write(unescape('%3Cscript src="//code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"%3E%3C/script%3E'));
    document.write(unescape('%3Clink rel="stylesheet" href="//code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css"%3E%3C/script%3E'));
    document.write(unescape('%3Clink rel="stylesheet" href="//code.jquery.com/mobile/1.1.0/jquery.mobile.structure-1.1.0.min.css"%3E%3C/script%3E'));
}
</script>

But if JavaScript is disabled, how to call stylesheets? 但如果禁用JavaScript,如何调用样式表?

If I use (I'm a bit stupid!)... 如果我使用(我有点傻!)......

<noscript>
<link rel="stylesheet" href="jqm/jquery.mobile-1.1.0.min.css" />
<link rel="stylesheet" href="jqm/jquery.mobile.structure-1.1.0.min.css" />
</noscript>

... My page is blank. ...我的页面是空白的。

Thanks for your help. 谢谢你的帮助。

Vincent 文森特

The Modernizr approach is to use JavaScript to add a class called "js" to the HTML tag on load, and remove a class called "no-js" which (in this case) you add yourself. Modernizr方法是使用JavaScript在加载时向HTML标记添加一个名为“js”的类,并删除一个名为“no-js”的类,在这种情况下,您自己添加。

Now, you can add some CSS styles only to descendants of .js and others only to descendants of .no-js , customizing either one to your liking. 现在,您可以只为.js后代添加一些CSS样式,而只为.no-js后代添加其他CSS样式,根据自己的喜好自定义任何一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM