3,055
社区成员
发帖
与我相关
我的任务
分享
<!-- 这个例子主要用来展示如何提取 单选按钮所选的值-->
<html>
<head>
<title>Test.html</title>
<script language="JavaScript">
function show(){
var str_name=document.myform.name.value;
document.write("姓名"+str_name); //显示姓名
var str_sex="";
if(document.myform.sex[0].checked){
str_sex=document.myform.sex[0].value;
}
else{
str_sex=document.myform.sex[1].value;
}
document.write("性别:"+str_sex); //显示性别
}
</script>
</head>
<body>
<form action="" name="myform" method="post">
姓名:<input type="text" name="name" ><br>
性别:<input type="radio" name="sex" value="男" checked="checked">男
<input type="radio" name="sex" value="女" >女<br>
<input type="button" value="查看" onclick="show()">
</form>
</body>
</html>
function show(){
var str_name=document.myform.name.value;
var str_sex="";
if(document.myform.sex[0].checked){
str_sex=document.myform.sex[0].value;
}
else{
str_sex=document.myform.sex[1].value;
}
document.write("姓名"+str_name); //显示姓名
document.write("性别:"+str_sex); //显示性别
}