jquery 控制checkbox

$(function(){
  //点击全选控制item checkbox是否选中
  $("#allschool").bind("click",function(){
    var ischecked = $("input[name='allschool']").attr("checked");
      $("[name=schoolids]:checkbox").each(function(){
        if(ischecked == 'checked')
        {
          $(this).attr("checked",true);
        }else{
          $(this).attr("checked",false);
        }
      });
  });
  //根据item checkbox控制是否全选
  $("[name=schoolids]:checkbox").bind("click",function(){
    var chk = $("[name=schoolids]:checkbox");
    $("#allschool").attr("checked",chk.length == chk.filter(":checked").length);
   });
});

  

posted @ 2014-02-28 11:55  风禾  阅读(225)  评论(0编辑  收藏  举报