简体   繁体   English

IE条件注释不起作用

[英]IE conditional comments not working

Why the following code download BOTH 2.0.2 and 1.9.1 in IE8? 为什么以下代码在IE8中同时下载2.0.21.9.1 (actually it's IE9 but in IE8 browser mode) (实际上是IE9,但在IE8浏览器模式下)

I am not so sure on the syntax, just copy/paste it from somewhere. 我不太确定语法,只需从某处复制/粘贴即可。 But it works as expect on Firefox (only download 2.0.2) and IE9 (only download 2.0.2 as well), but on IE8 (again, IE9 in IE8 browser mode) both files get downloaded. 但是它在Firefox(仅下载2.0.2)和IE9(也仅下载2.0.2)上按预期工作,但是在IE8(同样,在IE8浏览器模式下为IE9)上,两个文件都被下载。

<head>
    <!--[if lt IE 9]>
    <script src="{{STATIC_URL}}js/jquery-1.9.1.min.js"></script>
<![endif]-->

<!--[if gte IE 9]><!-->
    <script src="{{STATIC_URL}}js/jquery-2.0.2.min.js"></script>
<!--<![endif]-->
</head>

BONUS question: What's the complication if both jquery files are downloaded? 奖励问题:如果同时下载了两个jquery文件,会有什么并发症?

The correct code according to MS is: 根据MS的正确代码是:

<head>
    <!--[if lt IE 9]>
    <script src="{{STATIC_URL}}js/jquery-1.9.1.min.js"></script>
<![endif]-->

<![if gte IE 9]>
    <script src="{{STATIC_URL}}js/jquery-2.0.2.min.js"></script>
<![endif]>
</head>

As you can see the first block is the same. 如您所见,第一个块是相同的。 The second block has had some syntax removed that was unnecessary and almost certainly what was confusing things. 第二个块删除了一些不必要的语法,几乎可以肯定是什么使事情变得混乱。 Additionally it uses the "downlevel-revealed" syntax of conditional comments which will display on everything that doesn't recognise this conditional comment syntax. 此外,它使用条件注释的“下层显示”语法,该语法将在无法识别该条件注释语法的所有内容上显示。

Searching for "internet explorer conditional comments" was all that was needed to find this definitive help page: http://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx 查找此最终帮助页只需要搜索“ Internet Explorer条件注释”: http : //msdn.microsoft.com/zh-cn/library/ms537512(v=vs.85).aspx

On further investigation your original code looks like it was based on that given in http://blog.jquery.com/2013/03/01/jquery-2-0-beta-2-released/ . 经过进一步调查,您的原始代码看起来像是基于http://blog.jquery.com/2013/03/01/jquery-2-0-beta-2-released/中给出的代码一样。 I would guess therefore that this should work and therefore your problems are more likely coming from your rather interesting test environment which is both IE8 and IE9 at the same time. 因此,我想这应该可行,因此,您的问题更有可能来自您相当有趣的测试环境,即同时是IE8和IE9。

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

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