我需要浏览器为客户端浏览器下载合适的脚本。 我需要某种可行的 switch 语句吗?
我有;
- (common.css) 所有浏览器脚本都需要这个文件
- (ie6.css) IE 6 脚本
- (ie7.css) IE 7 脚本
- (ie8.css) IE 8 脚本
- (ie9.css) IE 9 脚本
- (other.css) Mozilla + Firefox + Safari 对所有版本使用相同的样式
我有(但没用)
<link rel="stylesheet" href="common.css" type="text/css" />
<!--[if IE 6 ]>
<link rel="stylesheet" href="ie6.css" type="text/css" />
<!--[elseif IE 7 ]>
<link rel="stylesheet" href="ie7.css" type="text/css" />
<!--[elseif IE 8 ]>
<link rel="stylesheet" href="ie8.css" type="text/css" />
<!--[elseif IE 9 ]>
<link rel="stylesheet" href="ie9.css" type="text/css" />
<!--[else]>
<link rel="stylesheet" href="other.css" type="text/css" />
<![endif]-->
问。我从另一个文件中破解了上面的代码,但无法让它工作? 如果我弄错了,是否可以使用更好的 switch 语句类型?
最佳答案
我相当确定您必须分别执行每个条件,而不是在 switch 语句中
<link rel="stylesheet" href="common.css" type="text/css" />
<!--[if IE 6 ]>
<link rel="stylesheet" href="ie6.css" type="text/css" />
<![endif]-->
<!--[if IE 7 ]>
<link rel="stylesheet" href="ie7.css" type="text/css" />
<![endif]-->
<!--[if IE 8 ]>
<link rel="stylesheet" href="ie8.css" type="text/css" />
<![endif]-->
<!--[if IE 9 ]>
<link rel="stylesheet" href="ie9.css" type="text/css" />
<![endif]-->
如果不是IE
<!--[if !IE]> -->
<link rel="stylesheet" href="other.css" type="text/css" />
<!-- <![endif]-->
关于html - CSS 文件选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11060528/