日期:2014-05-16  浏览次数:20322 次

JQ ie全选复选框正常,FF下只显示一次!
$('label').click(function(){
if ($(".box-all").attr("checked")){
$(".box-all").attr("checked",false);
$(".box-items").each(function(){
    $(this).attr("checked",false);
});
}else{
$(".box-all").attr("checked",true);
    $(".box-items").each(function(){
    $(this).attr("checked",true);
});
}
})


<label><input type="checkbox" class="box-all" /><span>全选</span></label><br>
<input type="checkbox" class="box-items"/><br>
<input type="checkbox" class="box-items"/><br>
<input type="checkbox" class="box-items"/><br>
<input type="checkbox" class="box-items"/><br>
<input type="checkbox" class="box-items"/><br>


哪位兄弟帮我看看FF下为什么不正常?

------解决方案--------------------
完整的测试代码

<script src="jquery-1.10.2.min.js"></script>

<script>
$(function(){
$('label').click(function(){
$(".box-items").each(function(){
    $(this).prop("checked",!!$(".box-all").prop("checked"));
});
});
});
</script>

<label><input type="checkbox" class="box-all" /><span>全选</span></label><br>
<input type="checkbox" class="box-items"/><br>
<input type="checkbox" class="box-items"/><br>
<input type="checkbox" class="box-items"/><br>
<input type="checkbox" class="box-items"/><br>
<input type="checkbox" class="box-items"/><br>



注意jquery版本