全选
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>全选</title> <script type="text/javascript"> window.onload=function(){ var oBtn=document.getElementById('btn'); var aInput=document.getElementsByTagName('input'); var i=0; oBtn.onclick=function(){ // aInput[0].checked=true; for(i=0;i<aInput.length;i++){ if(aInput[i].checked==true){ aInput[i].checked=false; }else{ aInput[i].checked=true; } } } // for(i=0;i<5;i++){ // alert(i); // } } </script> </head> <body> <p id="btn">全选</p> <input type="checkbox"/><br/> <input type="checkbox"/><br/> <input type="checkbox"/><br/> <input type="checkbox"/><br/> <input type="checkbox"/><br/> <input type="checkbox"/><br/> <input type="checkbox"/><br/> <input type="checkbox"/><br/> <input type="checkbox"/><br/> <input type="checkbox"/><br/> </body> </html>