x

开发者

c# .net

导航

input checkbox 全选

 1 <!DOCTYPE Html>  
 2 
 3 02 <html>  
 4 
 5 03     <head>  
 6 
 7 04         <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>  
 8 
 9 05         <script type="text/javascript">  
10 
11 06             function selectAll(checkbox) {  
12 
13 07                 $('input[type=checkbox]').attr('checked', $(checkbox).attr('checked'));  
14 
15 08             }  
16 
17 09         </script>  
18 
19 10     </head>  
20 
21 11     <body>  
22 
23 12         <input type="checkbox" onclick="selectAll(this);" />全选<br/>  
24 
25 13         <input type="checkbox"  /><br/>  
26 
27 14         <input type="checkbox"  /><br/>  
28 
29 15         <input type="checkbox"  /><br/>  
30 
31 16         <input type="checkbox"  /><br/>  
32 
33 17         <input type="checkbox"  /><br/>  
34 
35 18         <input type="checkbox"  /><br/>  
36 
37 19         ……  
38 
39 20     </body>  
40 
41 21 </html> 
 
//全选
04 function select_all(){
05     $("input[name='id']").attr("checked", true);
06 }
07   
08 //全不选
09 function unselect_all(){
10     $("input[name='id']").attr("checked", false); 
11 }
12   
13 //反向选择
14 function select_other(){
15     jQuery.each($("input[name='id']"), function(i, n){
16     n.checked = !n.checked;
17     }); 
18 }

posted on 2012-04-22 18:05  开发模式  阅读(7864)  评论(0编辑  收藏  举报

x