javascript 中radio不能点击选中 怎么解决
<!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>无标题页</title>
<script type="text/javascript" language="javascript">
function create()
{
var oRad1 = document.createElement("input");
oRad1.setAttribute("type","radio");
oRad1.setAttribute("id","rad1");
oRad1.setAttribute("name","aaa");
var oRad2 = document.createElement("input");
oRad2.setAttribute("type","radio");
oRad2.setAttribute("id","rad2");
oRad2.setAttribute("name","aaa");
document.body.appendChild(oRad1);
document.body.appendChild(oRad2);
}
</script>
</head>
<body>
<input id="Button1" type="button" value="button" onclick="create()" />
</body>
</html> 这是IE的一个bug吧...完美的写法是这样:[code]<!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>无标题页</title>
<script type="text/javascript" language="javascript">
function createElement(type, name) {
var element = null;
try {
element = document.createElement('<'+type+' name="'+name+'">');
} catch (e) {
}
if (!element) {
element = document.createElement(type);
element.name = name;
}
return element;
}
function create()
{
var oRad1 = createElement("input","aaa");
oRad1.setAttribute("type","radio");
oRad1.setAttribute("id","rad1");
oRad1.setAttribute("value","1");
var oRad2 = createElement("input","aaa");
oRad2.setAttribute("type","radio");
oRad2.setAttribute("id","rad2");
document.body.appendChild(oRad1);
document.body.appendChild(oRad2);
}
</script>
</head>
<body>
<input id="Button1" type="button" value="button" onclick="create();" />
</body>
</html>[/code] 谢谢
页:
[1]
