<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<form name="f1">
<table border="1">
<tr>
<th colspan="2">信息统计表</th>
</tr>
<tr>
<td>姓名:</td>
<td><input type="text" name="userName" /></td>
</tr>
<tr>
<td>年龄:</td>
<td><input type="text" name="old" /></td>
</tr>
<tr>
<td>性别:</td>
<td>
<input type="radio" name="sex" value="1" />男
<input type="radio" name="sex" value="0" />女
</td>
</tr>
<tr>
<td>爱好:</td>
<td>
<input type="checkbox" name="ah" value="1" />旅游 <br />
<input type="checkbox" name="ah" value="2" />登山 <br />
<input type="checkbox" name="ah" value="3" />健身 <br />
<input type="checkbox" name="ah" value="4" />上网 <br />
<input type="checkbox" name="ah" value="5" />游泳<br />
<input type="button" value="全选" onclick="selectAll()" />
<input type="button" value="取消" onclick="unSelectAll()" />
</td>
</tr>
<tr>
<td>学历</td>
<td>
<select name="xl">
<option value="">--请选择--</option>
<option value="1">专科</option>
<option value="2">本科</option>
<option value="3">硕士</option>
<option value="4">博士及以上</option>
</select>
</td>
</tr>
<tr>
<td>自我介绍:</td>
<td><textarea name="more" rows="5" cols="30"></textarea></td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="提交" onclick="return check()" />
<input type="reset" value="重置" />
</td>
</table>
</form>
<script type="text/javascript">
function check() {
//姓名不能为空
var name=document.f1.userName.value;
if(name==""){
alert("请输入姓名");
return false;
}
//年龄不能小于15岁
var age=document.f1.old.value;
if(age<15){
alert("年龄不能小于15");
return false;
}
//判断性别
var sex=document.f1.sex.value;
if(sex==1){alert("欢迎先生");}
else{alert("欢迎女士");}
//学历不能为空
var degree=document.f1.xl.value
if(degree==""){
alert("请选择学历");
return false;
}
//显示自我介绍
var intro=document.f1.more.innerHTML;
alert(intro);
}
function selectAll(){
var y=document.f1.ah;
for(var i=0;i<y.length;i++){
y[i].checked=true;
}
}
function unSelectAll(){
var y=document.f1.ah;
for(var i=0;i<y.length;i++){
y[i].checked=false;
}
}
</script>
</body>
</html> |