Jquery 中 $('obj').attr('checked',true)失效的几种解决方案

1:

$('obj').prop('checked',true)

2:

$(':checkbox').each(function(){

    this.checked=true;

});

attr为失效?因为checked属于为原型对象的属性。而attr在remove原型对象时会出错。原型对象指的是自身自带的,无法移除。prop会忽略这个错误。而attr操作的是普通非原型对象(可移除)。js 的dom对象属性是可以随意增加的。

posted @ 2015-12-02 14:04  PeterZhaoChina  阅读(438)  评论(0编辑  收藏  举报