jquery兼容不支持ie8浏览器的解决办法:1、使用语句【266c419352a525843049eb7155ebf872】可在ie8模式下进行一些兼容操作;2、为不支持foreach的浏览器添加自定义foreach方法。
本教程操作环境:windows7系统、jquery3.2.1版本,dell g3电脑。
推荐:jquery视频教程
jquery兼容不支持ie8浏览器的解决办法:
1、ie8不支持jquery版本解决办法
通过判断ie浏览器的版本来加载对应版本的jquery
使用语句266c419352a525843049eb7155ebf872仅ie8可识别 1b771f47d72d900ba74308aee59557f0 可在ie8模式下进行一些兼容操作。代码如下:
<script type="text/javascript" src="<%=path%>/js/jquery-3.1.1.min.js"></script><!--[if ie 8]><script type="text/javascript" src="<%=path%>/js/jquery-1.9.1.min.js"></script><![endif]-->
这样在切换到ie8时,低版本的jquery就会覆盖高版本的jquery。如果在ie8下需要调整某些元素的样式的话,最好将js代码放在页面底部(并注意是否有行内样式),不然为某些动态加载的内容设置的样式可能不会生效。
2、ie8不支持foreach解决办法
为不支持foreach的浏览器添加自定义foreach方法
代码如下:
if (typeof array.prototype.foreach != 'function') { array.prototype.foreach = function (callback) { for (var i = 0; i < this.length; i++) { callback.apply(this, [this[i], i, this]); } };}
如果是引入的jquery插件,可将该段代码放在插件内容的开头即可,这样在ie8下执行foreach方法就不会报错了。
3、ie8不支持map解决办法
添加自定义foreach方法
if (!array.prototype.map) { array.prototype.map = function(callback, thisarg) { var t, a, k; if (this == null) { throw new typeerror(" this is null or not defined"); } // 1. let o be the result of calling toobject passing the |this| value as the argument. var o = object(this); // 2. let lenvalue be the result of calling the get internal method of o with the argument "length". // 3. let len be touint32(lenvalue). var len = o.length >>> 0; // 4. if iscallable(callback) is false, throw a typeerror exception. // see: http://es5.github.com/#x9.11 if (typeof callback !== "function") { throw new typeerror(callback + " is not a function"); } // 5. if thisarg was supplied, let t be thisarg; else let t be undefined. if (thisarg) { t = thisarg; } // 6. let a be a new array created as if by the expression new array(len) where array is // the standard built-in constructor with that name and len is the value of len. a = new array(len); // 7. let k be 0 k = 0; // 8. repeat, while k < len while(k < len) { var kvalue, mappedvalue; // a. let pk be tostring(k). // this is implicit for lhs operands of the in operator // b. let kpresent be the result of calling the hasproperty internal method of o with argument pk. // this step can be combined with c // c. if kpresent is true, then if (k in o) { // i. let kvalue be the result of calling the get internal method of o with argument pk. kvalue = o[ k ]; // ii. let mappedvalue be the result of calling the call internal method of callback // with t as the this value and argument list containing kvalue, k, and o. mappedvalue = callback.call(t, kvalue, k, o); // iii. call the defineownproperty internal method of a with arguments // pk, property descriptor {value: mappedvalue, : true, enumerable: true, configurable: true}, // and false. // in browsers that support object.defineproperty, use the following: // object.defineproperty(a, pk, { value: mappedvalue, writable: true, enumerable: true, configurable: true }); // for best browser support, use the following: a[ k ] = mappedvalue; } // d. increase k by 1. k++; } // 9. return a return a; };}
相关免费学习推荐:js视频教程
以上就是jquery兼容不支持ie8浏览器怎么办的详细内容。
