Javascript 未捕获的类型错误:无法读取未定义的属性“msie” - jQuery 工具
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14923301/
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
Uncaught TypeError: Cannot read property 'msie' of undefined - jQuery tools
提问by Colin747
I am getting the following error in Chrome dev console:
我在 Chrome 开发控制台中收到以下错误:
Uncaught TypeError: Cannot read property 'msie' of undefined
My understanding is that it is because .browseris now deprecated in jQuery however I am using the latest version of jQuery tools and it is still giving the error, I checked in the jsfile and it is there.
我的理解是,这是因为.browser现在在 jQuery 中已被弃用,但是我使用的是最新版本的 jQuery 工具,它仍然给出错误,我检查了js文件,它就在那里。
How can I get around this so it does not give the error?
我怎样才能解决这个问题,所以它不会给出错误?
采纳答案by Alexander
The $.browsermethod has been removed as of jQuery 1.9.
从$.browserjQuery 1.9 开始,该方法已被删除。
The
jQuery.browser()method has been deprecated since jQuery 1.3 and is removed in 1.9. If needed, it is available as part of the jQuery Migrate plugin.We recommend using feature detection with a library such as Modernizr.
该
jQuery.browser()方法自 jQuery 1.3 起已弃用,并在 1.9 中删除。如果需要,它可以作为 jQuery Migrate 插件的一部分使用。我们建议将特征检测与 Modernizr 等库结合使用。
As stated in the Upgrade Guide you can try using the jQuery Migrate pluginto restore this functionality and let jQuery Tools work.
正如升级指南中所述,您可以尝试使用jQuery Migrate 插件来恢复此功能并让 jQuery 工具工作。
回答by JrBriones
You can check out this solution by AJ. It's pretty straightforward, just copy and paste the following lines of code.
您可以通过 AJ 查看此解决方案。这很简单,只需复制并粘贴以下代码行即可。
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.;
}
})();
Reference:
参考:
回答by Manisha Srivastava
Use the following script tag in your jsp/js file:
在您的 jsp/js 文件中使用以下脚本标记:
<script src="http://code.jquery.com/jquery-1.9.0.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.js"></script>
this will work for sure.
这肯定会起作用。
回答by Atik Khan
I use below code after js file include and it's working now.
我在 js 文件包含之后使用下面的代码,现在它正在工作。
<script src="js/jquery-ui.min.js" type="text/javascript"></script>
<script type="text/javascript">
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.;
}
})();
</script>
回答by Pointy
Here is the jQuery Tools bug on GitHub. You can try one of the patches.
这是 GitHub 上的 jQuery 工具错误。您可以尝试其中一个补丁。
edit— it doesn't look to me as if jQuery Tools is getting much support. I personally would not begin a new project with a dependency on that library unless I were prepared to take over support myself.
编辑- 在我看来,jQuery Tools 并没有得到太多支持。除非我准备自己接管支持,否则我个人不会开始依赖于该库的新项目。
回答by userlond
I've simply added
我只是添加了
jQuery.browser = {
msie: false,
version: 0
};
after jquery script, because I don't care about IE anymore.
在 jquery 脚本之后,因为我不再关心 IE 了。
回答by Bugfixer
回答by LogicFirst
I was getting this error while using JQuery 1.10 and JQuery UI 1.8. I was able to resolve this error by updating to the latest JQuery UI 1.11.4.
我在使用 JQuery 1.10 和 JQuery UI 1.8 时遇到此错误。我能够通过更新到最新的 JQuery UI 1.11.4 来解决这个错误。
Steps to update JQuery UI from Visual Studio:
从 Visual Studio 更新 JQuery UI 的步骤:
- Navigate to Project or Solution
- Right click: "Manage NuGet Packages"
- On the left, click on "Installed Packages" tab
- Look for "JQuery UI (Combined library)" and click Update
- If found, Select it and click Update
- If not found, find it in "Online > nuget.org" tab on the left and click install. If the old version of Jquery UI version is still existing, it can be deleted from the project
- 导航到项目或解决方案
- 右键单击:“管理 NuGet 包”
- 在左侧,单击“已安装的软件包”选项卡
- 查找“JQuery UI(组合库)”并单击更新
- 如果找到,请选择它并单击更新
- 如果未找到,请在左侧的“在线 > nuget.org”选项卡中找到它,然后单击安装。如果旧版本的Jquery UI版本仍然存在,可以将其从项目中删除
回答by Arezoo
Use like blow
像打击一样使用
i use this command and solve
我使用这个命令并解决
"Uncaught TypeError: Cannot read property 'msie' of undefined" Error
“未捕获的类型错误:无法读取未定义的属性 'msie'”错误
if (/1\.(0|1|2)\.(0|1|2)/.test($.fn.jquery) || /^1.1/.test($.fn.jquery)) {
return;
}
回答by Lerin Sonberg
As I don't plan to support old MS IE versions at all, I've simply replaced all references to browser.msiewith false.
Not a nice solution, I know, but it works for me.
因为我不打算支持所有旧微软IE浏览器的版本,我已经简单地更换所有提及browser.msie有false。我知道这不是一个好的解决方案,但它对我有用。
(Actually, they appeared as !browser.msie, which could be omitted from the conditions.)
(实际上,它们显示为!browser.msie,可以从条件中省略。)

