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也还是无法关联……
可以改变,但是有限制 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>
<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>
<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也还是无法关联……
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>
如果是动态创建readio的话,建议用document.createElement("<input name='aaa'>")这样的方法来解决