选中个数
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>选中的 长度</title> </head> <body> <input type="checkbox" value="1" name="check" checked="checked"> <input type="checkbox" value="2" name="check"> <input type="checkbox" value="3" name="check"> <input type="button" value="你选中的个数" id="btn"> </body> <script type="text/javascript"> var btn=document.getElementById("btn"); btn.onclick=function(){ var newarr= new Array(); var items=document.getElementsByName('check'); for(i=0;i<items.length;i++){ if(items[i].checked){ newarr.push(items[i].value); } } alert(newarr.length) } </script> </html>