Home  >  Article  >  Backend Development  >  这段 javascript 代码 错哪了, 求解答

这段 javascript 代码 错哪了, 求解答

WBOY
WBOYOriginal
2016-06-13 13:41:16956browse

这段 javascript 代码 哪里错了, 求解答
全选功能失效:
代码如下:

HTML code
<!--

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>
      



------解决方案--------------------
用firebug,调试下就出来了
------解决方案--------------------
js最好用火狐的firbug调试。
------解决方案--------------------
all 是 js 保留字,不能作为函数名
------解决方案--------------------
探讨
var cnames=document.getElementsByName("arr[]");

------解决方案--------------------
探讨

all 是 js 保留字,不能作为函数名
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn