abstract:<!DOCTYPE html> <html dir="ltr"> <head> <meta charset="utf-8"> <title>全选<
<!DOCTYPE html> <html dir="ltr"> <head> <meta charset="utf-8"> <title>全选</title> <style media="screen"> .box{width:100px;height:130px;border:1px solid red;margin:50px auto;padding:10px;} .box div{border-bottom:1px solid red; padding-bottom:10px;margin-bottom:10px} </style> </head> <body> <div><div> <input type="checkbox" name="item[]" id="checkall" onclick="checkAll()" value=""><label for="checkall">全选</label><br></div> <input type="checkbox" name="item[]" value="">1<br> <input type="checkbox" name="item[]" value="">2<br> <input type="checkbox" name="item[]" value="">3<br> <input type="checkbox" name="item[]" value="">4</div> </body> <script type="text/javascript"> function checkAll(){ var checkall,item; checkall=document.getElementById('checkall'); item=document.getElementsByName("item[]"); for(var i=0;i<item.length;i++){ if(checkall.checked){ item[i].checked=true; }else{ item[i].checked=false; } } } </script> </html>
Correcting teacher:韦小宝Correction time:2019-03-13 09:15:44
Teacher's summary:全选在所有的网站中不管是前台还是后台基本上都有在使用 用处还是蛮的大的 要注意全选之后可以获取到全选的值 这才是全选的真正目的