IE8浏览器不兼容indexOf、forEach、map解决方法
1、indexOf
//不兼容
if(codeArr.indexOf(code) == -1){
//TODO
}
//修改后
if($.inArray(code,codeArr) == -1){
//TODO
}
2、forEach
IE8浏览器不兼容forEach,把所有forEach改成for
3、map
ie8浏览器不兼容map,需要引入以下代码
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");
}
var O = Object(this);
var len = O.length >>> 0;
if (typeof callback !== "function") {
throw new TypeError(callback + " is not a function");
if (thisArg) {
T = thisArg;
}
A = new Array(len);
k = 0;
while(k < len) {
var kValue, mappedValue;
if (k in O) {
kValue = O[ k ];
mappedValue = callback.call(T, kValue, k, O);
A[ k ] = mappedValue;
}
k++;
}
return A;
};
}
}
以上是编程学习网小编为您介绍的“IE8浏览器不兼容indexOf、forEach、map解决方法”的全面内容,想了解更多关于 前端知识 内容,请继续关注编程基础学习网。