救急~~,帮解决一下,多谢了~~
以下的代码,希望的效果是Add new后生成的每一行RadioBox是一个组的,
但下面的代码实际的效果是所有的行都是一个组的,为什么?
请大家帮忙解决一下,我错在哪儿了?
<html>
<head>
<script language= "javascript ">
idx = 0;
function addnew(){
idx = idx + 1;
var spanDemo = document.getElementById( "DEMO ");
spanDemo = spanDemo.cloneNode(true);
spanDemo.id = "DEMO "+idx;
spanDemo.style.display= 'block ';
var txtObj = spanDemo.getElementsByTagName( "input ")[0];
txtObj.name = "rad "+idx;
txtObj.id = txtObj.name;
var txtObj = spanDemo.getElementsByTagName( "input ")[1];
txtObj.name = "rad "+idx;
txtObj.id = txtObj.name;
var spanObj = document.getElementById( "Dynamic ");
spanObj.appendChild(spanDemo);
}
</script>
</head>
<body>
<span id= "DEMO " style= "display:none ">
<input type= "radio " name= "rad ">
<input type= "radio " name= "rad ">
</span>
<span id= "Dynamic "> </span>
<input type= "button " name= "btn " id= "btn " value= "add new " onclick= "addnew() ">
</body>
</html>
------解决方案--------------------不能直接这样赋name属性吧~``
------解决方案--------------------Name是只读属性,不能修改