<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>表单提交的三种方式
</title>
<script type="text/javascript">
function checkForm(){
if(document.form1.in1.value==""){
alert("用户名不能为空。。。");
}else if(document.form1.in2.value.length == 0){
alert("密码不能为空。。。");
}else{
alert("提交成功!");
form1.submit();
}
}
function checkForm2(){
if(document.form1.in1.value==""){
alert("用户名不能为空。。。");
return false;
}else if(document.form1.in2.value.length == 0){
alert("密码不能为空。。。");
return false;
}else{
alert("提交成功!");
return true;
}
}
function checkForm3(){
if(document.form1.in1.value==""){
alert("用户名不能为空。。。");
return false;
}else if(document.form1.in2.value.length == 0){
alert("密码不能为空。。。");
return false;
}else{
alert("提交成功!");
return true;
}
}
</script>
</head>
<body>
<form action="#" name="form1" method="post" onsubmit="return checkForm3()">
用户名:
<input type="text" name="in1"/><br>
密 码:
<input type="password" name="in2"/><br>
<input type="submit" value="提交"/>
</form>
</body>
</html>
转载请注明原文地址: https://www.6miu.com/read-21938.html