ie8 数组不支持.indexOf()这个方法

 1 if (!Array.prototype.indexOf){
 2                                     Array.prototype.indexOf = function(elt /*, from*/){
 3                                       var len = this.length >>> 0;
 4                                   
 5                                       var from = Number(arguments[1]) || 0;
 6                                       from = (from < 0)
 7                                            ? Math.ceil(from)
 8                                            : Math.floor(from);
 9                                       if (from < 0)
10                                         from += len;
11                                   
12                                       for (; from < len; from++){
13                                         if (from in this && this[from] === elt)
14                                           return from;
15                                       }
16                                       return -1;
17                                     };
18                                   }
IE8 数组没有.indexOf()这个方法,给它造一个,在你调用   arr.indexof('xxx')的前面,加入上面这段代码就可以了

posted @ 2021-08-26 16:23  星期7  阅读(72)  评论(0编辑  收藏  举报