关于单选按钮使用很简单的Demo。
<!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" />
<title>radio单选按钮使用2</title>
</head>
<body>
<!--
<input type="radio" name="sex" value="男" checked <input type="radio" name="sex" value="女" -->
<input type="radio" name="sex" value="男" checked >男
<input type="radio" name="sex" value="女" >女
<input name="show">
</body>
<script type="text/javascript">
//得到审核菜单元素
var c = document.getElementsByName("sex");
//页面加截后,先判断单选按钮
for(var i=0;i<c.length;i++){
if(c[i].checked){
if(c[i].value == '男'){
document.getElementsByName("show")[0].value = '张三';
}else if(c[i].value == '女'){
document.getElementsByName("show")[0].value = '李四';
}
}
}
//当执行事件后,再判断单选按钮
for(var i=0;i<c.length;i++){
c[i].onclick = function (obj){
if(this.value == '男'){
document.getElementsByName("show")[0].value = '张三';
}else if(this.value == '女'){
document.getElementsByName("show")[0].value = '李四';
}
};
}
/*function test(obj){
alert(obj.value);
if(obj.value == '男'){
document.getElementsByName("show")[0].value = '张三';
}else if(obj.value == '女'){
document.getElementsByName("show")[0].value = '李四';
}
}
*/
</script>
</html>
转载于:https://blog.51cto.com/quietboy/1322055