zoukankan      html  css  js  c++  java
  • $.browser.msie' 为空或不是对象

    '$.browser.msie' 为空或不是对象,这个是jQuery错误

    出现这个错误,是因为升级了jQuery版本,从1.9以前升级到1.9以后,因为$.browser.msie在1.9以后的jQuery中不存在了,所以报错。



    jQuery 1.9 移除了 $.browser 的替代方法
    $.browser是通过正则表达式来匹配userAgent来判断浏览器版本和种类的.jquery1.3.2版本的文档中已经声明jquery.browser及jquery.browser.version建议弃用,可以使用jquery.support来代替。


    jQuery 从 1.9 版开始,移除了 $.browser 和 $.browser.version , 取而代之的是 $.support 。 在更新的 2.0 版本中,将不再支持 IE 6/7/8。 以后,如果用户需要支持 IE 6/7/8,只能使用 jQuery 1.9或者jQuery 1.10.1等。 如果要全面支持 IE,并混合使用 jQuery 1.9 和 2.0, 官方的解决方案是:

    <!--[if lt IE 9]>
    <script src='http://keleyi.com/keleyi/pmedia/jquery-1.10.1.min.js'></script>
    <![endif]-->
    <!--[if gte IE 9]>
    <script src='http://keleyi.com/keleyi/pmedia/jquery-2.0.2.min.js'></script>
    <![endif]-->

    从长久来看,这样有利于在复杂情况下根据浏览器特性进行分别处理, 而不是简单的检测浏览器类型和版本。 但目前很多旧程序的移植恐怕无法直接过渡为根据浏览器支持特性, 所以在网上找了一些能够直接替换的解决办法。
    判断浏览器类型:


    $.browser.mozilla = /firefox/.test(navigator.userAgent.toLowerCase());
    $.browser.webkit = /webkit/.test(navigator.userAgent.toLowerCase());
    $.browser.opera = /opera/.test(navigator.userAgent.toLowerCase());
    $.browser.msie = /msie/.test(navigator.userAgent.toLowerCase());

    等号后面的表达式返回的就是 true/false, 可以直接用来替换原来的 $.browser.msie 等。

    检查是否为 IE6:
    // Old
    if ($.browser.msie && 7 > $.browser.version) {}
    // New
    if ('undefined' == typeof(document.body.style.maxHeight)) {}

    检查是否为 IE 6-8:
    if (!$.support.leadingWhitespace) {}

    原文地址:http://blog.csdn.net/chenghaibing2008/article/details/12509305

  • 相关阅读:
    mac c++编译出现segmentation fault :11错误
    ssh 连接缓慢解决方法
    237. Delete Node in a Linked List
    203. Remove Linked List Elements
    Inversion of Control Containers and the Dependency Injection pattern
    82. Remove Duplicates from Sorted List II
    83. Remove Duplicates from Sorted List
    SxsTrace
    使用CCleaner卸载chrome
    decimal and double ToString problem
  • 原文地址:https://www.cnblogs.com/wei-dong/p/5868054.html
Copyright © 2011-2022 走看看