var   chk   =   document.createElement( "input");
  chk.setAttribute( "name",   "day");
  chk.setAttribute( "type",   "checkbox");
  chk.setAttribute( "ID",   idstr);
  chk.setAttribute( "value",   arrvalue);  
  chk.setAttribute( "class",   "datechk"); 
 var oTextNode = document.createTextNode(arrvalue);        
  var spn = document.createElement("span");
                       spn.setAttribute( "ID",   "span"+idstr);
  spn.appendChild(chk);           
  spn.appendChild(oTextNode);
  liobj.appendChild(spn);
查了一下发现 "input在IE中生成时有name属性,怎么办呢

解决方案 »

  1.   

    这是完整测试,现在出错请问如何修改
    <script>
    window.onload=function(){
        var obj=document.getElementById('SelectType');
        for(i=0;i<2;i++) 
        {  
         var liobj = document.createElement( "li");
         for(ii=0;ii<5;ii++) 
         {  
              var chk = document.createElement( "input");
              chk.setAttribute( "name", "Cc[]");
              chk.setAttribute( "type", "checkbox");
              chk.setAttribute( "ID","ClassID");
              chk.setAttribute( "value", "100");  
              chk.setAttribute( "class", "datechk");    
              var oTextNode = document.createTextNode("第项");        
              var spn = document.createElement("span");
              spn.appendChild(chk);           
              spn.appendChild(oTextNode);
              liobj.appendChild(spn);     }
         obj.appendChild(liobj); 
         }
        }
    </script>
    <body>
    <form name="mainform" action="" method="post">
         <div id="SelectType"></div>
         </form>
    </body>
    <script>
      alert(document.getElementById('SelectType').innerHTML);
    var len = document.mainform.day.length; 
    </script>
      

  2.   

    <script>
    window.onload=function(){
        var obj=document.getElementById('SelectType');
        for(i=0;i<2;i++) 
        {  
         var liobj = document.createElement( "li");
         for(ii=0;ii<5;ii++) 
         {  
              var chk = document.createElement( "input");
              chk.setAttribute( "name", "Cc[]");
              chk.setAttribute( "type", "checkbox");
              chk.setAttribute( "ID","ClassID");
              chk.setAttribute( "value", "100");  
              chk.setAttribute( "class", "datechk");    
              var oTextNode = document.createTextNode("第项");        
              var spn = document.createElement("span");
              spn.appendChild(chk);           
              spn.appendChild(oTextNode);
              liobj.appendChild(spn);     }
         obj.appendChild(liobj); 
         }
        }
    </script>
    <body>
    <form name="mainform" action="" method="post">
         <div id="SelectType"></div>
         </form>
    </body>
    <script>
          alert(document.getElementById('SelectType').innerHTML);
        var len = document.all.mainform.day.length; 
    </script>
      

  3.   

    上面ie适用
    为了兼容使用id获取form
    <script>
    window.onload=function(){
        var obj=document.getElementById('SelectType');
        for(i=0;i<2;i++) 
        {  
         var liobj = document.createElement( "li");
         for(ii=0;ii<5;ii++) 
         {  
              var chk = document.createElement( "input");
              chk.setAttribute( "name", "Cc[]");
              chk.setAttribute( "type", "checkbox");
              chk.setAttribute( "ID","ClassID");
              chk.setAttribute( "value", "100");  
              chk.setAttribute( "class", "datechk");    
              var oTextNode = document.createTextNode("第项");        
              var spn = document.createElement("span");
              spn.appendChild(chk);           
              spn.appendChild(oTextNode);
              liobj.appendChild(spn);     }
         obj.appendChild(liobj); 
         }
          alert(document.getElementById('SelectType').innerHTML);    }
    </script>
    <body>
    <form id="myform" name="mainform" action="" method="post">
         <div id="SelectType"></div>
         </form>
    </body>
    <script>
    </script>
      

  4.   

     id="myform"取到了但如何取下在checkbox哪个是选中的呢
      

  5.   

    全部试了一次仍然出错,我想应是动态生成上的问题,我用手工加的代码是可以的
    重新做的示例
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> <head>
    <title> new document </title>  <meta name="generator" content="editplus" />
    <meta name="author" content="Gao YiXiang" />  <meta name="email" content="[email protected]" />  <meta name="keywords" content="javascript dhtml dom" />  
    <meta name="description" content="I love web development." />
    </head>
    <body>  
    <form id="myform" name="mainform" action="" method="post"> 
     <input name="parentId" type="checkbox" id="i1" />
    <input name="parentId" type="checkbox" id="i2" />
    <input name="parentId" type="checkbox" id="i3" />  
    <input name="parentId" type="checkbox" id="i4" />
       <div id="SelectType"> </div>
    </form>
    <script type="text/javascript">
    <!-- 
       var obj=document.getElementById('SelectType');
        for(i=0;i <2;i++) 
        {  
         var liobj = document.createElement( "li");
         for(ii=0;ii <5;ii++) 
         {  
              var chk = document.createElement( "<INPUT></INPUT>");
       
              chk.setAttribute( "type", "checkbox");
              chk.setAttribute( "ID","ClassID");
              chk.setAttribute( "value", "100");  
              chk.setAttribute( "class", "datechk");   
      chk.setAttribute( "Name", "day");
              var oTextNode = document.createTextNode("abc");        
              var spn = document.createElement("span");
        spn.setAttribute( "Name", "sday");
              spn.appendChild(chk);           
              spn.appendChild(oTextNode);
              liobj.appendChild(spn);     }
         obj.appendChild(liobj); 
         }
             alert(document.getElementById('SelectType').innerHTML);     var aT = document.getElementsByName('day'); 
       // var aT = document.getElementsByName('parentId');  //ie下可得到值 ff没试
     alert(aT[aT.length-1].id);
    </script>
    </body> 
    </html> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> <head>
    <title> new document </title>  <meta name="generator" content="editplus" />
    <meta name="author" content="Gao YiXiang" />  <meta name="email" content="[email protected]" />  <meta name="keywords" content="javascript dhtml dom" />  
    <meta name="description" content="I love web development." />
    </head>
    <body>  
    <form id="myform" name="mainform" action="" method="post"> 
     <input name="parentId" type="checkbox" id="i1" />
    <input name="parentId" type="checkbox" id="i2" />
    <input name="parentId" type="checkbox" id="i3" />  
    <input name="parentId" type="checkbox" id="i4" />
       <div id="SelectType"> </div>
    </form>
    <script type="text/javascript">
    <!-- 
       var obj=document.getElementById('SelectType');
        for(i=0;i <2;i++) 
        {  
         var liobj = document.createElement( "li");
         for(ii=0;ii <5;ii++) 
         {  
              var chk = document.createElement( "<INPUT></INPUT>");
       
              chk.setAttribute( "type", "checkbox");
              chk.setAttribute( "ID","ClassID");
              chk.setAttribute( "value", "100");  
              chk.setAttribute( "class", "datechk");   
      chk.setAttribute( "Name", "day");
              var oTextNode = document.createTextNode("abc");        
              var spn = document.createElement("span");
        spn.setAttribute( "Name", "sday");
              spn.appendChild(chk);           
              spn.appendChild(oTextNode);
              liobj.appendChild(spn);     }
         obj.appendChild(liobj); 
         }
             alert(document.getElementById('SelectType').innerHTML);     var aT = document.getElementsByName('day'); 
       // var aT = document.getElementsByName('parentId');  //ie下可得到值 ff没试
     alert(aT[aT.length-1].id);
    </script>
    </body> 
    </html> 
      

  6.   

    IE下可以这样 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> <head>
    <title> new document </title>  <meta name="generator" content="editplus" />
    <meta name="author" content="Gao YiXiang" />  <meta name="email" content="[email protected]" />  <meta name="keywords" content="javascript dhtml dom" />  
    <meta name="description" content="I love web development." />
    </head>
        <body>  
        <form id="myform" name="mainform" action="" method="post"> 
         <input name="parentId" type="checkbox" id="i1" />
        <input name="parentId" type="checkbox" id="i2" />
        <input name="parentId" type="checkbox" id="i3" />  
        <input name="parentId" type="checkbox" id="i4" />
           <div id="SelectType"> </div>
        </form>
        <script type="text/javascript">
        <!-- 
        var obj = document.getElementById('SelectType');
        for(i=0;i <2;i++) 
        {  
         var liobj = document.createElement("li");
         for(ii=0;ii <5;ii++) 
         {  
              var chk = document.createElement("<INPUT name='day'></INPUT>");
              chk.setAttribute("type", "checkbox");
              chk.setAttribute("id","ClassID");
              chk.setAttribute("value", "100");  
              chk.setAttribute("class", "datechk");   
              var oTextNode = document.createTextNode("abc");        
              var spn = document.createElement("span");
              spn.setAttribute("name", "sday");
              spn.appendChild(chk);           
              spn.appendChild(oTextNode);
              liobj.appendChild(spn);
         }
         obj.appendChild(liobj); 
        }
        alert(document.getElementById('SelectType').innerHTML);
        var aT = document.getElementsByName('day'); 
        // var aT = document.getElementsByName('parentId');  //ie下可得到值 ff没试
        alert(aT[aT.length-1].id);
        </script>
      </body> 
    </html>
      

  7.   

    就没有可ff ie同时使用的方法?
      

  8.   

    做下判断吧
    ele_name = document.all? "<INPUT name='day'></INPUT>" : "input";
    var chk = document.createElement(ele_name);
      

  9.   

    <script>
    window.onload=function(){
        var obj=document.getElementById('SelectType');
        for(i=0;i<2;i++) 
        {  
         var liobj = document.createElement( "li");
         for(ii=0;ii<5;ii++) 
         {  
              var chk = document.createElement( "input");
              chk.setAttribute("Name", "day");
              chk.setAttribute("type", "checkbox");
              chk.setAttribute("id","ClassID");
              chk.setAttribute("value", "100");  
              chk.setAttribute("class", "datechk");
              var oTextNode = document.createTextNode("第项");        
              var spn = document.createElement("span");
              spn.appendChild(chk);           
              spn.appendChild(oTextNode);
              liobj.appendChild(spn);     }
         obj.appendChild(liobj); 
         }
    document.getElementById('SelectType').innerHTML=document.getElementById('SelectType').innerHTML.replace(/Name/g,"name")
      var aT = document.getElementsByName('day')[0]; 
             alert(aT.id);    }
    </script>
    <body>
    <form name="mainform" action="" method="post">
         <div id="SelectType"></div>
         </form>
    </body>
    要注意大小写,Name开始大写,然后换为小写,这样在ie和ff下都通过了。
      

  10.   

    动态生成是这样写的:
     var chk = document.createElement( "<INPUT name='day'></INPUT>")获取:
    var d = document.getElementsByName("day")
    不用判断d.length,直接写即可
    for(i = 0;i<d.length;i++)
      

  11.   

    灌水机代码:www.dullwolf.cn/CSDNer.rar下载。
      

  12.   

    这样在ff下也不能用啊
    ar chk = document.createElement("<INPUT ID='abc' type='checkbox' name='day' ></INPUT>")      报错
    String contains an invalid character"  code: "5
      

  13.   

    <script>
    function ex()
    {
    for(i=0;i<10;i++)
    {
    var chk
    if(navigator.appName == "Microsoft Internet Explorer")
    {
    chk = document.createElement("<INPUT name=day type='checkbox' />");
    }
    else
    {
    chk = document.createElement("INPUT")
    chk.setAttribute("type","checkbox")
    chk.setAttribute("name","day")
    }
    chk.setAttribute("value",i)
    document.getElementById("mxh").appendChild(chk);
    }
    }function gex()
    {var chk = document.getElementsByName("day");
    for(i = 0;i<chk.length;i++)
    alert(chk[i].checked + " = " + chk[i].value)}
    </script>
    <body>
    <form name=f>
    <input type=button value="生成" onclick="ex()" />
    <input type=button value="获取" onclick="gex()" />
    <div id="mxh"></div>
    </form>
    </body>
      

  14.   

    也可以使用
    document.getElementById("mxh").innerHTML = "<input name='day' type='checkbox' /><input name='day' type='checkbox' /><input name='day' type='checkbox' />"
      

  15.   


    var day = document.getElementsByName("day");
    var len = day.length;  

      

  16.   

    如果对标签名input 操作,有没有通用的方法,完成删除或提取值
      

  17.   

    HTML code<script>
    window.onload=function(){
        var obj=document.getElementById('SelectType');
        for(i=0;i<2;i++) 
        {  
         var liobj = document.createElement( "li");
         for(ii=0;ii<5;ii++) 
         {  
              var chk = document.createElement( "input");
              chk.setAttribute("Name", "day");
              chk.setAttribute("type", "checkbox");
              chk.setAttribute("id","ClassID");
              chk.setAttribute("value", "100");  
              chk.setAttribute("class", "datechk");
              var oTextNode = document.createTextNode("第项");        
              var spn = document.createElement("span");
              spn.appendChild(chk);           
              spn.appendChild(oTextNode);
              liobj.appendChild(spn);     }
         obj.appendChild(liobj); 
         }
        document.getElementById('SelectType').innerHTML=document.getElementById('SelectType').innerHTML.replace(/Name/g,"name")
          var aT = document.getElementsByName('day')[0]; 
             alert(aT.id);    }
    </script>
    <body>
    <form name="mainform" action="" method="post">
         <div id="SelectType"></div>
         </form>
    </body>
    要注意大小写,Name开始大写,然后换为小写,这样在ie和ff下都通过了。