JQuery實現CheckBox的全選
腳本代碼如下:
<script>
$(function() {
$('#chkAll').click(function() {
if ($(this).attr("checked")) {
$("#chkHRCategory input:checkbox").each(function(){
$(this).attr("checked",'true');
});
}
else {
$("#chkHRCategory input:checkbox").each(function(){
$(this).removeAttr("checked");
});
}
});
$('#chkHRCategory').click(function() {
var count =0;
$("#chkHRCategory input:checkbox").each(function(){
if ($(this).attr("checked")) {
} else {
count = count+1;
}
});
if (count!=0) {
$('#chkAll').removeAttr("checked");
}
else {
$('#chkAll').attr("checked",'true');
}
});
});
</script>
實現效果如下:


浙公网安备 33010602011771号