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>

實現效果如下:

posted @ 2013-03-14 10:00  邪见  阅读(134)  评论(0)    收藏  举报