动态生成的radio不能设置name属性,导致不能显示选中状态,急等盼复。
<!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>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 无标题文档 </title>
<script type= "text/javascript ">
function createRadio(){
var r1 = document.createElement( "input ");
r1.type = "radio ";
r1.name = "kkkk ";
r1.value = "radio1 ";
document.body.appendChild(r1);
var r2 = document.createElement( "input ");
r2.type = "radio ";
r2.name = "kkkk ";
r2.value = "radio1 ";
document.body.appendChild(r2);
}
</script>
</head>
<body onload= "createRadio(); ">
</body>
</html>
实际上生成后,标签并没有name属性,导致不能显示选中状态(就是中间的小圆点)。
------解决方案--------------------用innerHTML来做吧
这个问题说过很多次了,name属性无法给值
要不也可以createElement( ' <input type= "radio " name= "rdo... "> ');