全选

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="author" content="">
<meta name="copyright" content="">
<title></title>
<script src="http://libs.baidu.com/jquery/1.3.1/jquery.js" type="text/javascript"></script>
<script>
$(function(){
    var $oCk=$("#ck1");
    var $aIpt=$("#div1 input");
    $oCk.click(function(){
        if($(this).attr('checked')){
            $aIpt.attr('checked',true);    
        }else{
            $aIpt.attr('checked',false);        
        }
    });    
    
    $aIpt.click(function(){
        if($("#div1").find('input:checked').length==$aIpt.length){
            $oCk.attr('checked',true);    
        }else{
            $oCk.attr('checked',false);        
        }
    });
});
</script>
</head>

<body>
<input id="ck1" type="checkbox">
<hr>
<div id="div1">
  <input type="checkbox">
  <br>
  <input type="checkbox">
  <br>
  <input type="checkbox">
  <br>
  <input type="checkbox">
  <br>
</div>
</body>
</html>

 

posted @ 2016-11-29 16:45  Cutelady  阅读(156)  评论(0)    收藏  举报