abstract:for條件判斷是否出錯(cuò)????其中[]用法是否將聲明的i填入判斷的意思<!DOCTYPE html><html><head> <title>aaa</title> <meta charset="utf-8"> <style type="text/css"> .box{widt
for條件判斷是否出錯(cuò)????
其中[]用法是否將聲明的i填入判斷的意思
<!DOCTYPE html>
<html>
<head>
<title>aaa</title>
<meta charset="utf-8">
<style type="text/css">
.box{width: 120px;height: 250px;border: 1px solid #ccc;}
.box input{margin: 10px;}
</style>
</head>
<body>
<script type="text/javascript">//聲明all,執(zhí)行代碼{聲明ALL與NU,獲取ALL與NU。條件循環(huán)判斷I=0,當(dāng)I的長都小于NU,I值相加}
function all(){
var all,nu;
all=document.getELenmentById("all")
nu=document.getELenmentsByName("nu")
for(var i=0;i<nu.length;i++){
if(all.checked){
nu[i].checked=true;
}
else{nu[i].checked=false;}
}
</script>
<div class="box">
<div><input type="checkbox" id="all" onclick="all()"><label for="all"></label>全選</div>
<input type="checkbox" name="nu[]">選項(xiàng)1<br>
<input type="checkbox" name="nu[]">選項(xiàng)2<br>
<input type="checkbox" name="nu[]">選項(xiàng)3<br>
<input type="checkbox" name="nu[]">選項(xiàng)4<br>
<input type="checkbox" name="nu[]">選項(xiàng)5<br>
<input type="checkbox" name="nu[]">選項(xiàng)6<br>
</div>
</body>
</html>
Correcting teacher:天蓬老師Correction time:2019-01-13 09:56:04
Teacher's summary:nu[i].checked=true;這行代碼很關(guān)鍵, 寫得不錯(cuò), 功能也能實(shí)現(xiàn),原生js比較難學(xué),要堅(jiān)持