[收集党]jquery实现“选择全部”

收集自 http://www.oschina.net/code/snippet_86510_2781

<html>
   <head>  
     <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>  
     <script type="text/javascript">  
        function selectGroup(checkbox,obj) {
           $('input[name='+obj+']').attr('checked', $(checkbox).attr('checked')); 
        }  
     </script>  
  </head>  

  <body>  
    <input type="checkbox" onclick="selectGroup(this,'grp1');" />选中GROUPA<br/>  
     GROUPA:<br/>
    <input type="checkbox" name="grp1" />11<br/>  
    <input type="checkbox" name="grp1" />22<br/>  
    <input type="checkbox" name="grp1" />33<br/><br/> 

    <input type="checkbox" onclick="selectGroup(this,'grp2');" />选中GROUPB<br/> 
    GROUPB:<br/>
    <input type="checkbox" name="grp2" />44<br/>  
    <input type="checkbox" name="grp2" />55<br/>  
    <input type="checkbox" name="grp2" />66<br/>  
  </body>  
</html> 

你可能感兴趣的:(JavaScript,html,jquery)