用了这种方式,可是只有第一次点击的时候会有全选的效果,之后就没有了,请问问题出在哪呢?
<input type="checkbox" class="checkAll" value="全选"/>全选
<input type="checkbox" name="subBox"/>选项1
<input type="checkbox" name="subBox"/>选项2
<input type="checkbox" name="subBox"/>选项3
<script>
$(".checkAll").click(function() {
$('input[name="subBox"]').attr("checked",this.checked);
});
var $subBox = $("input[name='subBox']");
$subBox.click(function(){
$(".checkAll").attr("checked",$subBox.length == $("input[name='subBox']:checked").length ? true : false);
})
</script>
对的,应该是在jq1.6之后只能用prop了