1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <button id="all">全选</button> <button id="fan">反选</button> <input type="checkbox" id="i1"/> <ul> <li><input type="checkbox"/>洗jio</li> <li><input type="checkbox" />按摩</li> <li><input type="checkbox" />拔罐</li> <li><input type="checkbox" />刮痧</li> <li><input type="checkbox" />推背</li> <li><input type="checkbox" />马萨基</li> <li><input type="checkbox" />spa</li> </ul> </body> </html> <script type="text/javascript"> var allCheckBox = document.getElementsByTagName("ul")[0].getElementsByTagName("input"); all.onclick = function(){ for(var i = 0; i < allCheckBox.length; i++){ allCheckBox[i].checked = true; } i1.checked = true; } fan.onclick = function(){ var count = 0; for(var i = 0; i < allCheckBox.length; i++){
allCheckBox[i].checked = !allCheckBox[i].checked; if(allCheckBox[i].checked == true){ count++; } } if(count == allCheckBox.length){ i1.checked = true }else{ i1.checked = false; } } for(var i = 0; i < allCheckBox.length; i++){ allCheckBox[i].onclick = function(){ var count = 0; for(var j = 0; j < allCheckBox.length; j++){ if(allCheckBox[j].checked == true){ count++; } } if(allCheckBox.length == count){ i1.checked = true; }else{ i1.checked = false; } } } </script>
|