js全选反选
2020-04-07 19:20 默默不语 阅读(137) 评论(0) 编辑 收藏 举报<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <div> <input type="checkbox" name="checkboxs" id="" value="咕咕" />咕咕<br> <input type="checkbox" name="checkboxs" id="" value="嘎嘎" />嘎嘎<br> <input type="checkbox" name="checkboxs" id="" value="嘟嘟" />嘟嘟<br> <input type="button" id="quanxuan" value="全选" /> <input type="button" id="quanbuxuan" value="全不选" /> <input type="button" id="fanxuan" value="反选" /> </div> <script type="text/javascript"> var checkboxs = document.getElementsByName("checkboxs"); document.getElementById("quanxuan").onclick=function(){ for(var i=0;i<checkboxs.length;i++){ checkboxs[i].checked = true; } } document.getElementById("quanbuxuan").onclick=function(){ for(var i=0;i<checkboxs.length;i++){ checkboxs[i].checked = false; } } document.getElementById("fanxuan").onclick=function(){ for(var i=0;i<checkboxs.length;i++){ checkboxs[i].checked = !checkboxs[i].checked; } } </script> </body> </html>