全选反选

<div class="js_mobile">
<input name="Fruit" type="checkbox" value="" />苹果 
<input name="Fruit" type="checkbox" value="" />桃子 
<input name="Fruit" type="checkbox" value="" />香蕉
<input name="Fruit" type="checkbox" value="" />梨 
</div>

<a class="js_all"><input name="Fruit" type="checkbox" value="" /> 全选</a>
<script type="text/javascript" src="../v4.0-js/plug/jquery.min.js"></script>
<script>
$(".js_all").on('click',function(){
var checktrue= $(".js_mobile :checkbox").size();
var chk = 0;
console.log('chk---'+chk);
console.log('checktrue---'+checktrue);
$(".js_mobile :checkbox").each(function () { 
        if($('.js_all :checkbox').prop("checked")==true){
chk++;
}
   });
   console.log('chk---aaa   '+chk);
if(checktrue==chk){
$(".js_mobile :checkbox").prop("checked",true);
return;
}
$(".js_mobile :checkbox").prop("checked",false);
});
</script>

猜你喜欢

转载自wyr123789.iteye.com/blog/2373471