[html]代码库
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Language" content="zh-cn" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>单选、复选框Demo</title>
<script type="text/javascript">
function getSelectedEffect(effects) {//获取效果选项
for ( var i = 0; i < effects.length; i++) {
if (effects[i].checked)
return effects[i].value;
}
return "[没有选择]";
}
function getSelectedPrograms(programs) {//获取栏目选项
var i, result = "";
for (i = 0; i < programs.length; i++) {
if (programs[i].checked)
result += programs[i].value + " ";
}
return result;
}
function showResult() {//显示提交结果
var msg = "你的系别:" + getSelectedEffect(document.myform.page_effect);
msg += "\n你的爱好:" + getSelectedPrograms(document.myform.program);
alert(msg);
}
</script>
</head>
<body>
<form name="myform">
系别:
<input type="radio" value="软件学院" name="page_effect" />
软件学院
<input type="radio" value="音乐系" name="page_effect" />
音乐系
<input type="radio" value="艺术系" name="page_effect" />
艺术系
<input type="radio" value="土木系" name="page_effect" />
土木
<input type="radio" value="电子系" name="page_effect" />
电子
<input type="radio" value="数学系" name="page_effect" />
数学
<p class="b">爱好:
<input type="checkbox" name="program" value="篮球" />
篮球
<input type="checkbox" name="program" value="足球" />
足球
<input
type="checkbox" name="program" value="羽毛球" />
羽毛球
<input
type="checkbox" name="program" value="美术" />
美术
<input type="checkbox"
name="program" value="唱歌" />
唱歌
<input type="checkbox" name="program"
value="散步" />
散步
<input type="checkbox" name="program" value="聊天" />
聊天
<input type="checkbox" name="program" value="读书" />
读书</p>
<input type="submit" name="Button1" value="提交" onclick="showResult()" />
</form>
</body>
</html>
[代码运行效果截图]