解决IE 8 不支持indexOf

function indexOf_Ie8(params) {
if (!Array.prototype.indexOf)
{
Array.prototype.indexOf = function(elt /*, from*/)
{
var len = this.length >>> 0;
var from = Number(arguments[1]) || 0;
from = (from < 0)
? Math.ceil(from)
: Math.floor(from);
if (from < 0)
from += len;
 
for (; from < len; from++)
{
if (from in this &&
this[from] === elt)
return from;
}
return -1;
};
}
}

在调用indexOf前調用該方法

 

posted @ 2019-08-28 11:25  Empress&  阅读(197)  评论(0编辑  收藏  举报