RT,在JS中如何设置select  name属性?我这么写的,是无效的: var sel=document.createElement("select");
 sel.setAttribute("name","xxx");
 //...求解啊!!

解决方案 »

  1.   


    var sel=document.createElement("select");
    sel.options.name="xxx"//name属性?
    sel.options[i].text="xxx" //option 的名字
      

  2.   

    不是option的name和value
    是select的
    eg:<select name="xxx">....</select>
      

  3.   

    <html>
        <head>
            <meta http-equiv="content-type" content="text/html; charset=utf-8">
            <META http-equiv="Content-Style-Type" content="text/css">    </head>
        <script language=javascript>
            window.onload=function(){
          
                   var sel= document.getElementById("sel");
                   sel.name="a";
                    alert(sel.name)
            }    </script>
         <body>
           <div><select id=sel name="aaa"><div>
        </body>
    </html>
      

  4.   

    TO:   
    BeenZ这样不行,我试过,在页面里也没有显示!
      

  5.   

    没显示alert语句还是?你的浏览器是什么啊?我在各个浏览器下面测试都通过了的啊
    发代码来看看
      

  6.   

     <body>
           <div><select id=sel name="aaa"><div>
        </body>
    你的代码有点小问题,你把select标签都写全了,再试试
      

  7.   

    你这样写:
    <script>
             function a(b){
    alert(b.innerHTML);
    }
        </script>
         <body>
           <div onclick="a(this)" >test<select id=sel></select><div>
        </body>你看DIV里面的select是不是有name的
      

  8.   


    <script language=javascript>
       window.onload=function(){
             var sel= document.createElement("<select name='aaa'>");
             document.getElementById("pad").appendChild(sel);
             alert(document.getElementById("aaa").name)
       }
        </script>
         <body>
           <div id="pad"><div>
        </body>
      

  9.   

    楼上地高人,这样做是不行的啊;
    你可以试试,输出 div 中的内容,看看select 是不是有name 的
      

  10.   

    如果你用IE8的带开发个工具(F12),可以跟踪到动态的DOM的,select有name的