[javascript]代码库
<!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>
<title>js检测表单</title>
<script language="javascript" type="text/javascript">
function checked() {
if (myform.user.value == "") {
alert("请输入您的姓名!");
return false;
}
if(!(myform.sex[0].checked || myform.sex[1].checked)){
alert("请选择性别!");
return false;
}
if(myform.age.value =="")
{
alert("请输入年龄!");
return false;
}
if(myform.age.value <= 10 || myform.age.value >= 50){
alert("年龄应为10-50岁之间!");
return false;
}
}
</script>
</head>
<body>
<form name="myform" method="post" onsubmit="return checked()">
姓名:
<input name="user" type="text" value="" size="8" />
<br />
<br />
性别:
<input name="sex" type="radio" value="nan" />
男
<input name="sex"
type="radio" value="nv" />
女 <br />
<br />
年龄:
<input name="age" type="text" size="8" />
<br />
<br />
<input type="submit" name="mysubmit" value="提交" />
</form>
</body>
</html>
[代码运行效果截图]