1.通过 attr('checked','checked') 来设置checkbox时,重复点击,虽然checked属性设置正确,但是checkbox没有被勾选 ,如下代码:(代码是全选功能)

$('#ckAll').click(function(){
            if($('#ckAll ').attr('checked') == 'checked'){
                $('#ckAll').removeAttr('checked');
            }else{
                $('#ckAll').attr('checked','checked');
            }
            if($('#ckAll').attr('checked') == 'checked'){
                $('.tab-list .ckbox').each(function(i,n){
                    $(n).attr('checked','checked');
                });
            }else{
                $('.tab-list .ckbox').each(function(i,n){
                    $(n).removeAttr('checked');
                });
            }
        }); 

2. 换成 prop('checked',true) ,当ckAll被选中时,所有列表checkbox都会被选中

//用click或用 change

$('#ckAll').click(function(){
            if($('#ckAll').prop('checked')){
                $('.tab-list .ckbox').each(function(i,n){
                    $(n).prop('checked',true);
                });
            }else{
                $('.tab-list .ckbox').each(function(i,n){
                    $(n).prop('checked',false);
                });
            }
        });

相关文章:

  • 2022-12-23
  • 2022-02-26
  • 2022-12-23
  • 2022-12-23
  • 2021-11-25
  • 2022-12-23
  • 2021-11-21
猜你喜欢
  • 2022-02-04
  • 2022-12-23
  • 2021-07-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案