有人可以帮我读一下这个吗?
<!--[if gt IE 8]><!-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<!--<![endif]-->
<!--[if lte IE 8]>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<![endif]-->
据我所知,如果当前浏览器大于 ie 8,我们最终会使用 1.9.1,如果当前浏览器小于或等于 8,我们最终会使用 1.7.2
我有几个问题;
第一个是如果浏览器不是IE怎么办?以 Chrome 为例。 上面的头代码到底是如何包含 JQuery 的呢?显然是这样,但不知道如何。条件是只寻址IE。不是吗?
其次,我对 snytax 感到困惑;
<!--[if gt IE 8]><!-->
部分看起来与 <!--[if lte IE 8]>
不同部分。额外的<!-->
前者让我困惑。
这是我从中获取片段的地方; http://bombdiggitydesign.com/crisp-2/Crisp-cool/index.html
它以某种方式为我加载 JQuery(我正在使用 Chrome)。
当我检查viewsource:
时,我看到了这个
<!--[if gt IE 8]><!-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="assets/js/jquery-1.9.1.min.js"><\/script>')</script>
<!--<![endif]-->
<!--[if lte IE 8]>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<![endif]-->
其中,只有 http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js在 chrome View 中是可点击的。因此,chrome 以某种方式通过了 <!--[if gt IE 8]><!-->
健康)状况。
显然,它有效,但我对如何操作感到困惑。
最佳答案
对于你的第一个问题,这是 IE conditional comments 的专长。 .
对于你的第二个问题,
<!--[if gt IE 8]><!--> //COMMENTS ENDS
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"/>
<!--<![endif]--> //COMMENTS ENDS
这不仅仅是为了方便而注释(准确地说是可读性)。 但是 jQuery 1.9.1 将在所有浏览器中运行。
但是,您的 jQuery 1.9.1 将被 jQuery 1.7.2 覆盖,仅在 IE <=7 浏览器中。
仅供引用:在 Internet Explorer 10 中,当页面处于标准模式(文档模式 10)时,不支持 HTML 条件注释
希望您能理解。
关于javascript - 无法解释此 <head> 片段中的 IE 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19167370/