<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>JavaScript笔记2</title>
<script type="text/javascript">
//验证:方法1
function Email(){
var email=document.getElementById("email").value;
if(email==""||email==null){
alert("Email不能为空!");
}
return false;
}
//验证:方法2
function validate_required(field,alerttxt){
with (field){
if (value==null||value==""){
alert(alerttxt);
return false;
}else {
return true;
}
}
}
function validate_form(thisform){
with (thisform){
if (validate_required(email,"Email must be filled out!")==false){
email.focus();
return false;
}
}
}
</script>
</head>
<body>
<!--验证:方法1-->
<form action="#" onsubmit=Email() method="post">
Email:<input type="text" id="email"/>
<input type="submit" value="提交" />
</form>
<!--验证:方法2-->
<form action="Main.html" onsubmit="return validate_form(this)" method="post">
Email: <input type="text" name="email" size="30">
<input type="submit" value="Submit">
</form>
</body>
</html>