加载jQuery的条件注释替代方案 [英] Conditional comments alternative to load jQuery

查看:109
本文介绍了加载jQuery的条件注释替代方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为jQuery 2+不支持IE 8,所以我需要使用以前的版本:jQuery 1.9。

Because jQuery 2+ doesn't support IE 8, I'll need to make use of a previous version: jQuery 1.9.

有没有办法包含jQuery 1.9在使用IE时使用IE< = 8和jQuery 2+> 8.
我尝试使用条件注释:

Is there a way to include jQuery 1.9 when using IE <= 8 and jQuery 2+ when using IE > 8. I tried it with Conditional comments:

<!--[if lt IE 9]><!--><script> .. googleapis jquery 1.9 .. </script><!--<![endif]-->
<!--[if gte IE 9]><!--><script> .. googleapis jquery 2+ .. </script><!--<![endif]-->

问题是它无法正常工作,我发现有关它的信息不再受支持了:< a href =http://msdn.microsoft.com/en-us/library/ie/hh801214(v=vs.85).aspx\"rel =nofollow> http://msdn.microsoft.com/en -us / library / ie / hh801214(v = vs.85).aspx

The problem is that It is not working and I found some information about it not being supported anymore: http://msdn.microsoft.com/en-us/library/ie/hh801214(v=vs.85).aspx

还有其他办法吗?

推荐答案

你希望IE8版本在一个注释掉的块中,但非IE9版本不是:

You want the IE8 version to be in a commented-out block, but the non-IE9 version not to be:

<!--[if lt IE 9]> <script> .. googleapis jquery 1.9 .. </script> <![endif]-->
<![if !IE|gte IE 9]> <script> .. googleapis jquery 2+ .. </script> <![endif]>

带警报的实时示例

IE8识别条件评论,但其他浏览器不识别(包括较新的IE)。

IE8 recognizes conditional comments, but other browsers don't (including newer IEs).

你也可能希望在第二个中有!IE ,只是为了完整性,如上所述。

You also probably want to have !IE in the second one, just for completeness, as above.

这篇关于加载jQuery的条件注释替代方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆