onsubmit的使用
<!DOCTYPE html>
<html>
<head>
<title>confirm.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script language="javascript">
function validate_email(field, alerttxt){
with(field){
var a1 = value.indexOf("@");
var a2 = value.lastIndexOf(".");
if(a1<2 || a2<2){
alert(alerttxt);
return false;
}else{
return true;
}
}
}
function validate_name(field,alerttxt){
with(field){
if(value.length<3){
alert(alerttxt);
return false;
}
}
}
function validate_form(thisForm){
with(thisForm){
if(validate_email(email,"邮箱不正确")==false){
email.focus();//光标移到email一栏
return false;
}
if(validate_name(name,"name不正确")==false){
name.focus();
return false;
}
}
}
</script>
</head>
<body>
<form action="" method="post" οnsubmit="return validate_form(this)">
姓名<input type="text" name="name" id="name" />
邮箱<input type="text" name="email" id="email" />
<input type="submit" value="提交" />
</form>
</body>
</html>