IE8浏览器对indexof()函数的兼容性

完美并不美cxm 2015-07-20 11:24:01
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');
}
}

求大神帮忙,急急急!!!!
...全文
321 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
天际的海浪 2015-07-20
  • 打赏
  • 举报
回复
staffIds确定是数组么??
hch126163 2015-07-20
  • 打赏
  • 举报
回复
staffIds.indexOf(this.id) 先确定 staffIds 是否是数组

87,988

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧