abstrak:<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>選擇框練習(xí)</title> <style type="text/css"> .check div{ border:&
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>選擇框練習(xí)</title> <style type="text/css"> .check div{ border: 1px solid red; border-radius: 5px; padding: 10px; } .check div p{ margin-bottom: 5px; border-bottom: 1px solid #552; } .check div p i{ float: right; } </style> <script type="text/javascript"> function checkAll(){ var check,allBox,xq; allBox=document.getElementById('allBox'); check=document.getElementsByName('check'); xq=document.getElementById('xq'); for (var i = 0; i < check.length; i++) { if (allBox.checked) { check[i].checked=true; xq.innerHTML="全不選"; }else{ check[i].checked=false; xq.innerHTML="全選"; } } } </script> </head> <body> <div> <div> <p><input type="checkbox" name="check"><a href="#">選擇框的運用</a><i>發(fā)布時間:2018-12-28</i></p> <p><input type="checkbox" name="check"><a href="#">選擇框的運用</a><i>發(fā)布時間:2018-12-29</i></p> <p><input type="checkbox" name="check"><a href="#">選擇框的運用</a><i>發(fā)布時間:2018-12-29</i></p> <p><input type="checkbox" name="check"><a href="#">選擇框的運用</a><i>發(fā)布時間:2018-12-29</i></p> <p><input type="checkbox" name="check"><a href="#">選擇框的運用</a><i>發(fā)布時間:2018-12-29</i></p> <p><input type="checkbox" name="check"><a href="#">選擇框的運用</a><i>發(fā)布時間:2018-12-29</i></p> <p><input type="checkbox" name="check"><a href="#">選擇框的運用</a><i>發(fā)布時間:2018-12-29</i></p> <p><input type="checkbox" name="check"><a href="#">選擇框的運用</a><i>發(fā)布時間:2018-12-29</i></p> <p><input type="checkbox" name="check"><a href="#">選擇框的運用</a><i>發(fā)布時間:2018-12-29</i></p> <p><input type="checkbox" name="check"><a href="#">選擇框的運用</a><i>發(fā)布時間:2018-12-29</i></p> <p><input type="checkbox" name="check"><a href="#">選擇框的運用</a><i>發(fā)布時間:2018-12-29</i></p> <p><input type="checkbox" name="check"><a href="#">選擇框的運用</a><i>發(fā)布時間:2018-12-29</i></p> <p><input type="checkbox" name="check"><a href="#">選擇框的運用</a><i>發(fā)布時間:2018-12-29</i></p> <p> <input type="checkbox" id="allBox" onclick=" checkAll()"><label for="allBox"><span id="xq">全選</span></label> <input type="checkbox" id="noBox" onclick="noCheck()"><label for="noBox">反選</label> </p> </div> </div> </body> </html>
Guru membetulkan:天蓬老師Masa pembetulan:2019-01-01 15:18:26
Rumusan guru:var check,allBox,xq; 在函數(shù)頭部,一次生的聲明變量,是一個不錯的好習(xí)慣