当我取消选中复选框时,我想取消选中“全部”复选框

 $('#All').click(function () { 
        var status = $(this).is(":checked"); 
        if (status) { 
            $.each($('input[name="checkbox"]'), function () { 
                this.checked = true; 
            }) 
            $('input[name="checkbox"]').attr("checked", "checked"); 
 
        } else { 
            $('input[name="checkbox"]').removeAttr("checked"); 
            $.each($('input[name="checkbox"]:checked'), function () { 
                this.checked = false; 
            }) 
        } 
 
    }) 

请您参考如下方法:

尝试使用这个

$(".all").click(function()  
{ 
var el=this; 
  $(".child").each(function(){     
   $(this).prop("checked",$(el).prop("checked"))   ; 
    }); 
     
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
<input type="checkbox"  class="all"/>All 
<input type="checkbox" class="child"/>one 
<input type="checkbox"  class="child"/>two 
<input type="checkbox"  class="child"/>three 
<input type="checkbox"  class="child"/>four


评论关闭
IT虾米网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!