jQuery attr方法 第一次有效,第二次无效问题

例如设置全选:

$(function(){
    //设置全选反选
        $("#all").click(function(){
        if(this.checked){ 
            $("input[name='id']").attr("checked",true);
        }else{   
            $("input[name='id']").attr("checked",false);
        }    
    }); 
}); 

点击all按钮 第一次全选有用第二次全选无效。因为jquery1.7以上的版本用此方法只能第一次好用,第二次就会失效,需要把 (":checkbox").attr("checked","checked"); (“:checkbox”).prop(‘checked’,false); $(“:checkbox”).prop(‘checked’,true)

猜你喜欢

转载自blog.csdn.net/poorCoder_/article/details/54922818