足下实训的选择源代码
<!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 Check()
{
var select_sex = document.getElementsByName("sex");
if((!document.getElementById("man").checked)&&(!document.getElementById("woman").checked))
{
alert("你什么都还没有选呢");
}
{
for(var i = 0;i<select_sex.length;i++)
{
if(select_sex[i].checked)
{
alert("选中了"+select_sex[i].value);
break;
}
}
}
}
function CheckSport()
{
var select_sport = document.getElementsByName("sport");
var arry = new Array();
var j = -1;
var f = "";
for(var i = 0;i<select_sport.length;i++)
{
if(select_sport[i].checked)
{
j++;
arry[j] = select_sport[i].value;
}
}
if(arry.length<1)
{
alert("你还什么都没有选呢");
}
else
{
for(var k=0;k<arry.length;k++)
{
f+=arry[k];
}
alert("我选择了"+f);
}
}
</script>
</head>
<body>
<label><input type="radio" name="sex" id="man" value="男"/>男</label>
<label><input type="radio" name="sex" id="woman" value="女"/>女</label>
<label><input type="button" name="check" id="btn_check" value="验证" onclick="Check()"/></label>
<p></p>
<label><input type="checkbox" name="sport" id="basketball" value="篮球"/>篮球</label>
<label><input type="checkbox" name="sport" id="football" value="足球"/>足球</label>
<label><input type="checkbox" name="sport" id="basketball" value="排球"/>排球</label>
<label><input type="button" name="check_sport" id="btn_checkSport" value="验证" onclick="CheckSport()"/></label>
</body>
</html>