读书人

JQ ie全选复选框通常FF下只显示一次

发布时间: 2013-12-26 00:35:35 作者: rapoo

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版本

读书人网 >JavaScript

热点推荐