Skip to content

Instantly share code, notes, and snippets.

@z007
Last active August 29, 2015 14:08
Show Gist options
  • Save z007/7e52500df4e59ba1345b to your computer and use it in GitHub Desktop.
Save z007/7e52500df4e59ba1345b to your computer and use it in GitHub Desktop.
复选框实例 d单选框实例
<!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>单选按钮实例</title>
<script type="text/javascript">
function getResult(){
for (var i = 0; i < document.myform.RadioButtons.length; i++) {
if (document.myform.RadioButtons[i].checked) {
alert("您是" + document.myform.RadioButtons[i].value + "血型");
break;
}
}
}
</script>
</head>
<body>
<form name="myform" action="" method="get">
<h2>请选择你的血型</h2>
<table border="1" width="200">
<tr>
<td>
<input type="radio" name="RadioButtons" value="A"/>A型
</td>
</tr>
<tr>
<td>
<input type="radio" name="RadioButtons" value="B"/>B型
</td>
</tr>
<tr>
<td>
<input type="radio" name="RadioButtons" value="AB"/>AB型
</td>
</tr>
<tr>
<td>
<input type="radio" name="RadioButtons" value="O"/>O型
</td>
</tr>
</table><hr><input type="button" value="确定" onClick="getResult()"/>
</form>
</body>
</html>
<!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>复选框实例</title>
<script type="text/javascript">
function getResult(){
var result = "";
for (var i = 0; i < document.myform.mycheckbox.length; i++) {
if (document.myform.mycheckbox[i].checked) {
result += " "+document.myform.mycheckbox[i].value;
}
}
alert("您选择的结果是:" + result);
}
</script>
</head>
<body>
<form name="myform" action="" method="get">
<h2>请选择你喜欢的水果</h2>
<table border="1" width="200">
<tr>
<td>
<input type="checkbox" name="mycheckbox" value="苹果"/>苹果
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="mycheckbox" value="香蕉"/>香蕉
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="mycheckbox" value="葡萄"/>葡萄
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="mycheckbox" value="桃子"/>桃子
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="mycheckbox" value="梨"/>梨
</td>
</tr>
</table><hr><input type="button" value="确定" onClick="getResult()"/>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment