abstract:<!-- 老师,麻烦你帮我看一下这段代码怎么不对? 后面例子我使用for语句可以,while就不行,应该也是哪里出问题了 var a,b; while (a>=0,b>=10,a+b=10){ document.write(a,b) a++,b--; } --> <!DOCTYPE html> <ht
<!-- 老师,麻烦你帮我看一下这段代码怎么不对? 后面例子我使用for语句可以,while就不行,应该也是哪里出问题了 var a,b; while (a>=0,b>=10,a+b=10){ document.write(a,b) a++,b--; } --> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> js全选测试</title> <style type="text/css"> .box{width: 200px;height: 300px;border: 1px solid #7c7c7c;border-radius: 10px;overflow: hidden;} .box_header{border-bottom: 1px solid #7c7c7c;} input{margin: 10px;} </style> <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 // } // } 测试for语句可行 var i=0; while(i<item.length;){ if (checkall.checked) { item[i].checked=true }else{ item[i].checked=false } i++; } } </script> </head> <body> <div> <div><input type="checkbox" id="checkall" onclick="checkAll()"><label for="checkall">全选</label></div> <input type="checkbox" name="item[]">选项1 <br> <input type="checkbox" name="item[]">选项1 <br> <input type="checkbox" name="item[]">选项1 <br> <input type="checkbox" name="item[]">选项1 <br> <!-- 测试使用id也可以 <input type="checkbox" id="item[]">选项2 <br> <input type="checkbox" id="item[]">选项3 <br> <input type="checkbox" id="item[]">选项4 <br> <input type="checkbox" id="item[]">选项5 <br> <input type="checkbox" id="item[]">选项1 <br> <input type="checkbox" id="item[]">选项2 <br> <input type="checkbox" id="item[]">选项3 <br> <input type="checkbox" id="item[]">选项4 <br> <input type="checkbox" id="item[]">选项5 <br> <input type="checkbox" id="item[]">选项1 <br> --> </div> </body> </html>
Correcting teacher:韦小宝Correction time:2019-01-28 09:12:05
Teacher's summary:细心点 你看看你这中间的分号 乱加啊 while(i<item.length;) 这里的条件你加分号干嘛的? var checkall,item,; 这里定义变量 已经有逗号了你还加分号干嘛 而且像这种js的错误 f12 是可以检查的