您的位置:首页 > Web前端 > JQuery

同时使用jQuery1.9和jQuery2.0要注意的地方

2014-03-09 18:49 573 查看
最新jQuery 2.0以及以上版本已经不再支持IE6/7/8,这看起来貌似不方便,但是从长远来看这是一个趋势也是必然的,淘汰旧事物使用新事物是技术发展的必然途径。

但是现在一些产品尤其是国内的web应用需要考虑到更多的用户依然在使用IE 7/8甚至是万恶的IE6,这时我们还得使用jQuery 1.9包括以下版本,但是如果我们既想支持IE6/7/8又想使用jQuery 2.0的新特性,那么就要注意以下几点。

$.browser.mozilla = /firefox/.test(navigator.userAgent.toLowerCase());//火狐
$.browser.webkit = /webkit/.test(navigator.userAgent.toLowerCase());//webkit为核心的浏览器
如chrome 或者safari 都是使用webkit为内核的浏览器,这些都是标准一样的
$.browser.opera = /opera/.test(navigator.userAgent.toLowerCase());//opera浏览器
$.browser.msie = /msie/.test(navigator.userAgent.toLowerCase());//IE浏览器

//同时我们如果发现 浏览器是IE时,还需要判断是否IE6,方法如下

// 第一种办法 不推荐
if ($.browser.msie &&   $.browser.version<7) {}
// 这个办法相对比较取巧
if ('undefined' == typeof(document.body.style.maxHeight)) {}
 //大家知道 在IE6的css中是不支持maxWidth和maxHeight的


<!--[if lt IE 9]>
    <script src='jquery-1.9.0.js'></script>
<![endif]-->
<!--[if gte IE 9]>
    <script src='jquery-2.0.0.js'></script>
<![endif]-->


if(!$.browser.msie)
 document.write("<script src='jquery-2.0.0.js'></script>");
else
 document.write("<script src='jquery-1.9.0.js'></script>");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: