IE8浏览器对indexof()函数的兼容性
function showSelected(){
//在页面加载时添加被选中职员
//alert('select')
var staffs = $(".list input[type=checkbox]:gt(0)");
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()函数前面,还是不可以解决IE8浏览器的兼容性问题?
staffs.each(function(){
if(staffIds.indexOf(this.id)>-1){在IE8中这个地方老是提示对象不支持此属性或方法
$(this).attr('checked',true);
}else{
//alert('jj')
$(this).attr('checked',false);
}
});
if($(".list input[type=checkbox]:checked").size()==$(".list input[type=checkbox]").size()-1){
$(".selectAll").attr('checked','true');
}
}
求大神帮忙,急急急!!!!