Home > Article > Backend Development > 这段 javascript 代码 错哪了, 求解答
这段 javascript 代码 哪里错了, 求解答
全选功能失效:
代码如下:
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> <script> document.write("<ul>"); for(var i=0;i<20;i++){ document.write("<li>"); document.write('<input type="checkbox" name="arr[]" value="'+i+'"> heihei'); document.write(""); } document.write(""); </script> <input id="ss" type="checkbox" onclick="all(this)">全选 <script> var cnames=document.getElementsByName("arr[]"); alert(cnames.length); function all(obj){ for(var i=0;i<cnames.length;i++) { cnames[i].checked=obj.checked; } } </script>