首页 > 其他 > 详细

checkbox全选、反选

时间:2017-05-26 12:33:46      阅读:255      评论:0      收藏:0      [点我收藏+]

<body>
  <div class="div1">
    <input type="checkbox" name="cb">
  </div>
  <hr>
  <div class="div2">
    <input type="checkbox" name="cbs"><br>
    <input type="checkbox" name="cbs"><br>
    <input type="checkbox" name="cbs"><br>
    <input type="checkbox" name="cbs">
  </div>
</body>
<script type="text/javascript">
  var num=0;
  $("input[name=‘cb‘]").click(function(){
    if($(this).attr("checked")=="checked"){
      $("input[name=‘cbs‘]").attr("checked",true);
      num=$("input[name=‘cbs‘]").length;
    }else{
      $("input[name=‘cbs‘]").attr("checked",false);
      num=0;
    }
  })
  $("input[name=‘cbs‘]").click(function(){
    if($(this).attr("checked")=="checked"){
      num++;
      if(num==$("input[name=‘cbs‘]").length){
        $("input[name=‘cb‘]").attr("checked",true);
      }
    }else{
      num--;
      $("input[name=‘cb‘]").attr("checked",false);
    }
  })
</script>

checkbox全选、反选

原文:http://www.cnblogs.com/pengyan89/p/6907749.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!