製作複選框的全選/全不選效果
阿新 • • 發佈:2018-11-03
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>全選功能測試</title> <script type="text/javascript"> function a() { var all = document.getElementById("all").checked; var others = document.getElementsByTagName("input"); for(var i = 0; i < others.length; i++) { others[i].checked = all; } } </script> </head> <body> <input type="checkbox" value="運動" name="interests" />運動 <input type="checkbox" value="游泳" name="interests" />游泳 <input type="checkbox" value="打球" name="interests" />打球 <input type="checkbox" value="爬山" name="interests" />爬山 <input type="checkbox" value="跑步" name="interests" />跑步 <br /> <input type="checkbox" value="全選" name="interests" onclick="a()" id="all"/>全選 </body> </html>