jquery报错:jquery.tools.min.js:15 Uncaught TypeError: Cannot read property 'msie' of undefined
背景:
首页用到了jquery.tools.min.js这个插件,用于轮播图的显示,但是突然就不行了,谁也没动,之前也没有出现过,查看控制台,报错显示:jquery.tools.min.js:15 Uncaught TypeError: Cannot read property 'msie' of undefined
解决
查阅博客发现,这是由于不支持之前的jquery才出错的。到现在解决方法有两种:
一、将代码粘贴进去源码保存即可
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.$1;}
})();
至于粘贴的位置:
先找到jquery.tools.min.js这个文件,格式化代码,然后ctrl+f查找msie:
a.tools = a.tools || {version: "v1.2.7"}, a.tools.overlay = {addEffect: function (a, b, d) {c[a] = [b, d]},conf: {close: null,closeOnClick: !0,closeOnEsc: !0,closeSpeed: "fast",effect: "default",fixed: !a.browser.msie || a.browser.version > 6, //重点在这行left: "center",load: !1,mask: null,oneInstance: !0,speed: "normal",target: null,top: "10%"}
};
然后在这个方法的上面添加这段代码就行:
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.$1;}
})();
所以完整的代码:
(function (a) {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.$1;}})();a.tools = a.tools || {version: "v1.2.7"}, a.tools.overlay = {addEffect: function (a, b, d) {c[a] = [b, d]},conf: {close: null,closeOnClick: !0,closeOnEsc: !0,closeSpeed: "fast",effect: "default",fixed: !a.browser.msie || a.browser.version > 6,left: "center",load: !1,mask: null,oneInstance: !0,speed: "normal",target: null,top: "10%"}};var b = [], c = {};a.tools.overlay.addEffect("default", function (b, c) {var d = this.getConf(), e = a(window);d.fixed || (b.top += e.scrollTop(), b.left += e.scrollLeft()), b.position = d.fixed ? "fixed" : "absolute", this.getOverlay().css(b).fadeIn(d.speed, c)}, function (a) {this.getOverlay().fadeOut(this.getConf().closeSpeed, a)});......
二、使用插件jQuery Migrate来修复bug
下载链接的话,可以百度。
结论
你的先确定你是jquery.tools.min.js这个插件所造成的的问题。博主使用的是第一种方法,可以解决问题。第二种没试过。至于为什么要这样改,请看参考资料。
- [jQuery] Cannot read property ‘msie’ of undefined错误的解决方法
- [JQUERY] CANNOT READ PROPERTY ‘MSIE’ OF UNDEFINED错误的解决方法