【问题标题】:TypeError: jQuery.browser is undefinedTypeError: jQuery.browser 未定义
【发布时间】:2014-08-14 06:39:49
【问题描述】:

我正在使用 jquery mobile 1.4.2 和脚本 1.11.0

我已经阅读了之前提出的有关此问题的问题,但我不知道如何在我的代码中使用。

这是我的代码

脚本

jQuery("input[name^='cat']").bind(jQuery.browser.msie ? 'click' : 'change', function(event) {   
var id = jQuery(this).attr('id');
mantener_seleccion(id);//its a function name
 });  

如果我运行它,它会显示类似“TypeError: jQuery.browser is undefined”的错误 请任何人帮助我。

【问题讨论】:

标签: javascript jquery


【解决方案1】:

Ankur Modi 的答案有效,但我将为您通过安全连接工作的用例添加一个。

浏览器会通过安全连接过滤掉混合内容,因此您需要手动导入 JS migrate 1.0.0 并安装它。在我的用例中,我们使用 ASP.Net MVC 5x 和旧 JS 小部件的混搭。

  1. 使用 NuGet 包管理器安装 JS 迁移。我安装了 1.0.0,因为它解决了我的问题。较新的版本没有解决我的具体问题。
  2. 在 BundleConfig.cs 添加以下行:

            bundles.Add(new ScriptBundle("~/bundles/jqmigrate").Include(
                    "~/Scripts/jquery-migrate-1.0.0.js"));
    
  3. 在 _Layout.cshtml 中,将以下行添加到“Scripts.Render”部分的底部:

    @Scripts.Render("~/bundles/jqmigrate")
    

    您现在应该不会再收到错误消息了。

【讨论】:

  • 这如何回答这个问题?
【解决方案2】:

只需在您的 code.work 中添加以下脚本。

<script src="http://code.jquery.com/jquery-migrate-1.0.0.js"></script>

请参阅此链接了解更多信息。 https://github.com/Studio-42/elFinder/issues/469

【讨论】:

  • 这在您通过安全连接工作时不起作用,浏览器会将其过滤掉。
【解决方案3】:

jQuery.browser 已弃用。 此属性已在 jQuery 1.9 中删除

Demo

使用navigation.userAgent

if(navigator.userAgent.toUpperCase().indexOf('MSIE') >= 0){
    alert("IE")
}

使用这个sn-p:

var isIE = navigator.userAgent.toUpperCase().indexOf('MSIE') >=0 ? 'click' : 'change' ;

jQuery("input[name^='cat']").bind(isIE , function(event) {   
    var id = jQuery(this).attr('id');
    mantener_seleccion(id);//its a function name
});

【讨论】:

    猜你喜欢
    • 2020-10-05
    • 2017-06-22
    • 2018-10-12
    • 2014-06-21
    • 2014-08-06
    • 2022-10-13
    • 2018-06-02
    • 2017-02-18
    • 2012-12-30
    相关资源
    最近更新 更多