代码
1 <head>
2 <title>JQuery实现全选</title>
3 <script language="javascript" type="text/javascript" src="file:///G:/programming/js/jQuery1.3.2/jquery-1.3.2.min.js"></script>
4 <script type="text/javascript">
5 function selectall()
6 {
7 if($("#selectall").attr("checked")==true)
8 {
9 $(":checkbox").each(function(){$(this).attr("checked",true);})
10 }
11 else
2 <title>JQuery实现全选</title>
3 <script language="javascript" type="text/javascript" src="file:///G:/programming/js/jQuery1.3.2/jquery-1.3.2.min.js"></script>
4 <script type="text/javascript">
5 function selectall()
6 {
7 if($("#selectall").attr("checked")==true)
8 {
9 $(":checkbox").each(function(){$(this).attr("checked",true);})
10 }
11 else
12 {
13 $(":checkbox").each(function(){$(this).attr("checked",false);})
14 }
15 }
16 </script>
17 </head>
18 <body>
19 <input type='checkbox' />UserA
20 <input type='checkbox' />UserB
21 <input type='checkbox' />UserC
22 <input type="checkbox" id="selectall" onclick="selectall()" />全选
23 </body>
24 </html>
25
13 $(":checkbox").each(function(){$(this).attr("checked",false);})
14 }
15 }
16 </script>
17 </head>
18 <body>
19 <input type='checkbox' />UserA
20 <input type='checkbox' />UserB
21 <input type='checkbox' />UserC
22 <input type="checkbox" id="selectall" onclick="selectall()" />全选
23 </body>
24 </html>
25
代码比较简单,不会的可以查一下jquery的API,很容易明白的!