全选全不选
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="Generator" content="EditPlus®"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> <title>Document</title> </head> <script type="text/javascript"> <!-- function checkAll(flag){ //拿到所有的多选框 var hobbys = document.getElementsByName("hobby"); //循环赋值 for(var i = 0; i < hobbys.length; i++){ hobbys[i].checked = flag; } } function reverseCheck(){ //拿到所有的多选框 var hobbys = document.getElementsByName("hobby"); //循环赋值,取反 for(var i = 0; i < hobbys.length; i++){ hobbys[i].checked = !hobbys[i].checked; } } //--> </script> <body> 全选/全不选 <input type="checkbox" name="hobbys" onclick="checkAll(this.checked)"> <br><br> 反选 <input type="checkbox" name="hobbys" onclick="reverseCheck()"> <br><br> <input type = "checkbox" name="hobby" value="football">足球 <input type = "checkbox" name="hobby" value="football">篮球 <input type = "checkbox" name="hobby" value="football">棒球 <input type = "checkbox" name="hobby" value="football">乒乓球 <input type = "checkbox" name="hobby" value="football">橄榄球 <input type = "checkbox" name="hobby" value="football">网球 <input type = "checkbox" name="hobby" value="football">马球 </body> </html>