setAttribute("name","group3");
和x.name="group3";
都试过了,貌似不行哦……~求教

解决方案 »

  1.   

     <BODY>
    <SCRIPT LANGUAGE="JavaScript">
    function changeName(){
    document.getElementById('bbb').name='aaa';
    alert(document.getElementById('bbb').name);
    }
    </SCRIPT>
    <INPUT TYPE="radio" id="bbb" NAME="bbb">bbb<br>
    <input type="button" value="changeName" onclick="changeName()"/>
     </BODY>
      

  2.   

    别用x.name,你那个x不是节点对象,是你在js里的变量而已
      

  3.   

    3楼的方法我之前已经试过了,虽然name值改变了,但2个radio无法关联……
    <script language="javascript">
      function changeName() {
        var x=document.getElementsByTagName("input");
        var y=x[0].parentNode;
        var z=document.createElement("input");
        z.setAttribute("type","radio");
        z.setAttribute("value","g2");
        y.replaceChild(z,x[0]);
        x[2].value="test";
      }
    </script>
    我这样做了之后,新生的radio也还是无法关联……
      

  4.   

    可以改变,但是有限制
    Microsoft JScript® allows the name to be changed at run time. 
    This does not cause the name in the programming model to change in the collection of elements, 
    but it does change the name used for submitting elements.
    L@_@K
    <!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="" />
      <meta name="keywords" content="" />
      <meta name="description" content="" />
     </head> <body>
    <input type="radio" name="group1" >value1 </input> 
    <input type="radio" name="group2" >value2 </input> 
    <input type="button" value="changeName" onClick="changeName();"> 
     </body>
     <script type="text/javascript">
     <!--
    function changeName()
    {
    var o1 = document.getElementsByName("group1")[0];
    alert(o1.name); // group1
    o1.name = "group2";
    alert(o1.name); // group2
    alert(document.getElementsByName("group1").length); // 1
    }
     //-->
     </script>
    </html>
      

  5.   

    firefox可以改,IE下失败
    如果是动态创建readio的话,建议用document.createElement("<input name='aaa'>")这样的方法来解决
      

  6.   

    这种直接更改了name属性后的radio,和其他radio不能关联到一起,成了name相同的多选框了。
      

  7.   

    没错,name 值可以改,但是2个radio仍无法关联,文档里已经说滴很清楚了!