日期:2014-05-16 浏览次数:20381 次
<!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=utf-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<title>无标题文档</title>
</head>
<body>
<select name="sex" id="sex" size="1">
<option value="1">body</option>
<option value="2">girl</option>
</select>
<div id="sexoption">
</div>
<input type="button" id="btn" value="choose" />
<script type="text/javascript">
document.getElementById('btn').onclick=function(){
var s=document.getElementById('sex');
var rehtml="";
var radioName=s.getAttribute('name');
for(var i=0;i<s.options.length;i++){
rehtml+="<input type=\"radio\" name=\""+radioName+"\" value=\""+ s.options[i].value+"\"/>"+s.options[i].text;
}
var racontainer=document.getElementById('sexoption');
if(racontainer.getElementsByTagName('input').length>1){
document.getElementById('sexoption').innerHTML="";
}else{
document.getElementById('sexoption').innerHTML= rehtml;
}
}
</script>
</body>
</html>