1

我认为如果条件不满足,条件注释会指示浏览器忽略内容?!

例如,如果 IE6 是浏览器,我只想包含一个样式表。以下位于页面的 <HEAD> 元素中。

<!--[if IE 6]>
  <link id="IE6StyleSheet" rel="Stylesheet" type="text/css" href="~/css/IE6.css" runat="server" />
<![endif]-->

或者

<!--[if IE 6]>
  <link rel="Stylesheet" type="text/css" href="../css/IE6.css" />
<![endif]-->

为什么 IE7、IE8 和 FF3 都加载该样式表?!

注意:将条件更改为 [if lte IE 6] 没有任何区别!:(

重大更新

我是个白痴……我才注意到我做错了什么!我给出的示例稍作修改。App_Themes下的css文件的路径!当然,css总是被加载!!!

4

1 回答 1

2

尝试:

<!--[if lte IE 6]>
   <link id="IE6StyleSheet" rel="Stylesheet" type="text/css" href="../css/IE6.css" />
<![endif]-->

这只会加载 IE6 或更低版本的样式表。这是您可以使用的测试脚本,它将打印出您正在使用的 IE 版本:

<p><!--[if IE]>
According to the conditional comment this is Internet Explorer<br />
<![endif]-->
<!--[if IE 5]>
According to the conditional comment this is Internet Explorer 5<br />
<![endif]-->
<!--[if IE 5.0]>
According to the conditional comment this is Internet Explorer 5.0<br />
<![endif]-->
<!--[if IE 5.5]>
According to the conditional comment this is Internet Explorer 5.5<br />
<![endif]-->
<!--[if IE 6]>
According to the conditional comment this is Internet Explorer 6<br />
<![endif]-->
<!--[if IE 7]>
According to the conditional comment this is Internet Explorer 7<br />
<![endif]-->
<!--[if gte IE 5]>
According to the conditional comment this is Internet Explorer 5 and up<br />
<![endif]-->
<!--[if lt IE 6]>
According to the conditional comment this is Internet Explorer lower than 6<br />
<![endif]-->
<!--[if lte IE 5.5]>
According to the conditional comment this is Internet Explorer lower or equal to 5.5<br />
<![endif]-->
<!--[if gt IE 6]>
According to the conditional comment this is Internet Explorer greater than 6<br />
<![endif]-->
</p>

您不应该在 Firefox 中看到带有此测试代码的任何文本。

于 2009-04-27T21:04:53.630 回答