全部选中复选框

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3  <head>
 4   <title> new document </title>
 5   <meta name="generator" content="editplus" />
 6   <meta name="author" content="" />
 7   <meta name="keywords" content="" />
 8   <meta name="description" content="" />
 9   <script type="text/javascript">
10   function test(sta){
11     var chk = document.getElementsByTagName('input');
12     for (var i=0;i<7 ;i++ ){
13         chk[i].checked= sta;
14 
15     }
16   }
17   </script>
18  </head>
19 
20  <body>
21  <input type="checkbox" value="" /><br/>
22  <input type="checkbox" value="" /><br/>
23  <input type="checkbox" value="" /><br/>
24  <input type="checkbox" value="" /><br/>
25  <input type="checkbox" value="" /><br/>
26  <input type="checkbox" value="" /><br/>
27  <input type="checkbox" value="" /><br/>
28 
29   <input type="button" value="全选"onclick="test('checked');">
30    <input type="button" value="全不选"onclick="test('');">
31  </body>
32 </html>
原文地址:https://www.cnblogs.com/a2762/p/4107705.html