<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <input type="checkbox" id="cid" onclick="selectAll()" /> <table> <tr><td><input type="checkbox" name="ck" /></td><td>张三</td></tr> <tr><td><input type="checkbox" name="ck" /></td><td>张a</td></tr> <tr><td><input type="checkbox" name="ck" /></td><td>张b</td></tr> <tr><td><input type="checkbox" name="ck" /></td><td>张c</td></tr> <tr><td><input type="checkbox" name="ck" /></td><td>张d</td></tr> </table> <script type="text/javascript"> function selectAll(){ var cks=document.getElementsByName("ck"); var temp=document.getElementById("cid"); for(i=0;i<cks.length;i++){ if(temp.checked==true){ cks[i].checked=true; }else{ cks[i].checked=false; } } } </script> </body> </html>