jQuery 无法获取未定义或空引用的属性“msie”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19359680/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 23:46:34  来源:igfitidea点击:

Unable to get property 'msie' of undefined or null reference

jqueryjqgrid

提问by Andre Lombaard

I'm trying to create a JQGrid in my MVC 4 view and getting a

我正在尝试在我的 MVC 4 视图中创建一个 JQGrid 并获得一个

Unable to get property 'msie' of undefined or null reference

无法获取未定义或空引用的属性“msie”

error when adding the JQGrid javascript files

添加 JQGrid javascript 文件时出错

bundles.Add(new ScriptBundle("~/Bundles/Shared/JS").Include(
            "~/Scripts/jquery-1.9.1.min.js",
            "~/Scripts/jquery.validate.min.js",
            "~/Scripts/bootstrap.js",
            "~/Content/silviomoreto-bootstrap-select/bootstrap-select.min.js",
            "~/Scripts/js/Shared/Index.js",
            "~/Scripts/js/Shared/Validation.js",
            "~/Scripts/jquery.placeholder.js",
            "~/Content/jquery.jqGrid-4.4.3/js/i18n/grid.locale-en.js",
            "~/Content/jquery.jqGrid-4.4.3/js/jquery.jqGrid.min.js"));

The error occurs on the following line

错误发生在以下行

e=n.browser.msie&&"6.0"==n.browser.version

Any idea why this is happening?

知道为什么会这样吗?

回答by James Allardice

From the jQuery docs for jQuery.browser:

来自 jQuery 文档jQuery.browser

This property was removed in jQuery 1.9and is available only through the jQuery.migrate plugin. Please try to use feature detection instead.

此属性已在 jQuery 1.9 中删除,并且只能通过 jQuery.migrate 插件使用。请尝试改用特征检测。

So you'll have to drop down to an older version of jQuery or use the migrate plugin.

因此,您必须使用旧版本的 jQuery 或使用migrate 插件

回答by Anand

I also had similar problem as this property was removed in jQuery 1.9... Add below code inside your page script tag.

我也有类似的问题,因为这个属性在 jQuery 1.9 中被删除了......在你的页面脚本标签中添加下面的代码。

 jQuery.browser = {};
  (function () {
   jQuery.browser.msie = false;
   jQuery.browser.version = 0;
   if (navigator.userAgent.match(/MSIE ([0-9]+)\./)) {
    jQuery.browser.msie = true;
    jQuery.browser.version = RegExp.;
   }
})();

回答by Mozak

e=n.browser.msie&&"6.0"==n.browser.version

e=n.browser.msie&&"6.0"==n.browser.version

I guess it should be like this

我想应该是这样的

e == n.browser.msie && "6.0"==n.browser.version

or e === n.browser.msie && "6.0"=== n.browser.versionfor strict equality

e === n.browser.msie && "6.0"=== n.browser.version严格平等

回答by RobNHood

I had a similar problem with another older script of mine however the majority of users will be running a version of IE over 6.0 so it really was not a big deal for me to give support to 6.0 or below. What I did was just change the line that said

我的另一个旧脚本也有类似的问题,但是大多数用户将运行 6.0 以上的 IE 版本,因此支持 6.0 或以下版本对我来说真的没什么大不了的。我所做的只是改变了那句话

var isIE6 = ($.browser.msie && &.browser.version < 7);

to

var isIE6 = false;