Javascript 未捕获的类型错误:无法读取未定义的属性“msie”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14793331/
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-24 17:56:45  来源:igfitidea点击:

Uncaught TypeError: Cannot read property 'msie' of undefined

javascriptjquery

提问by Abram

This error message is arising from the following code:

此错误消息是由以下代码引起的:

$.fn.extend({
    chosen: function(options) {
      if ($.browser.msie && ($.browser.version === "6.0" || $.browser.version === "7.0")) {

From the file: https://github.com/koenpunt/chosen/edit/master/chosen/chosen.jquery.js

来自文件:https: //github.com/koenpunt/chosen/edit/master/chosen/chosen.jquery.js

Obviously browser is not defined. Any idea what could be causing this. Same error in Chrome and FF.

显然浏览器没有定义。知道是什么原因造成的。Chrome 和 FF 中的错误相同。

回答by Matt Greer

$.browserwas removed from jQuery starting with version 1.9. It is now available as a plugin. It's generally recommended to avoid browser detection, which is why it was removed.

$.browser从 1.9 版开始从 jQuery 中删除。它现在可以作为插件使用。通常建议避免浏览器检测,这就是它被删除的原因。