摘要:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>全選</title>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>全選</title> <style> .box{width: 120px;height: 220px;border: 1px solid #000;margin: 10px auto;padding: 5px 10px} .box div{border-bottom: 1px solid #444444;padding-bottom: 8px;margin-bottom: 8px} input{margin: 6px 10px} </style> <script> function checkAll() { var checkall=document.getElementById('checkall') //變量獲取id var one=document.getElementsByClassName('item') //變量獲取class for(var i=0;i<one.length;i++ ){ //循環(huán)語句 if(checkall.checked){ //判斷checkall是否被勾選 one[i].checked=true //item全選 } else{ one[i].checked=false //否則不 } } } </script> </head> <body> <div class="box"> <div> <input type="checkbox" id="checkall" onclick="checkAll()"><label for="checkall">全選</label> </div> <input type="checkbox" class="item">選項(xiàng)1<br> <input type="checkbox" class="item">選項(xiàng)2<br> <input type="checkbox" class="item">選項(xiàng)3<br> <input type="checkbox" class="item">選項(xiàng)4<br> <input type="checkbox" class="item">選項(xiàng)5<br> <input type="checkbox" class="item">選項(xiàng)6<br> </div> </body> </html>
批改老師:查無此人批改時(shí)間:2019-05-05 09:35:49
老師總結(jié):完成的不錯(cuò)。js每行語句最后增加;號。繼續(xù)加油。