这是我写的一个注册页面 带JS验证的 问题就是不管怎样 总是能提交 为什么啊?AJAX那里用来验证邮箱是否重复 重复则把输入框置空,这样点击提交还是返回FALSE,但是不管怎样就是能提交,我什么都不填也能跳,为什么啊??用了点BOOTSTRAP的框架,但是这只是样式 应该没影响啊?
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'register.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" src="bootstrap/jquery-3.2.1.min.js" ></script>
<script type="text/javascript" src="bootstrap/bootstrap.min.js" ></script>
<link rel="stylesheet" href="bootstrap/bootstrap.min.css" />
<script type="text/javascript">
function checkEmail(){
var userEmail = document.getElementById("uEmail").value;
var ets = document.getElementById("emailts");
if(!isEmail(userEmail)){
ets.innerHTML ="邮箱格式不正确!";
ets.style.color="red";
return false;
}else{
ets.innerHTML = "";
}
var j = 0;
$.post("/mydemo/servlet/UserServlet",{"userEmail":userEmail,"action":"registerV"},
function(data){
if(data == "emailExist"){
ets.innerHTML = userEmail+"已经被注册";
ets.style.color="red";
document.getElementById("uEmail").value = null;
ets.innerHTML ='邮箱已被注册!';
ets.style.color='red';
}
});
ets.innerHTML ="邮箱可以使用!";
ets.style.color="green";
return true;
}
function checkPass(){
var userPass = document.getElementById("uPass").value;
var pts = document.getElementById("passts");
if(userPass.length<6 || userPass.length >15)
{
pts.innerHTML ="密码长度须在6-15之间!";
pts.style.color="red";
return false;
}
pts.innerHTML ="密码可以使用!";
pts.style.color="green";
return true;
}
function checkRpass(){
var userPass = document.getElementById("uPass").value;
var userRPass =document.getElementById("uRPass").value;
var prts = document.getElementById("passrts");
if (userPass != userRPass) {
prts.innerHTML="两次密码输入不一致!";
prts.style.color="red";
return false;
}
prts.innerHTML ="输入一致!";
prts.style.color="green";
return true;
}
function checkMobile(){
var tel = document.getElementById("tel").value;
var telts = document.getElementById("telts");
if(!isMobile(tel)){
telts.innerHTML ="手机号格式不正确!";
telts.style.color="red";
return false;
}
telts.innerHTML ="手机号正确!";
telts.style.color="green";
return true;
}
function isEmail(str){
var reg = /[a-z0-9-]{1,30}@[a-z0-9-]{1,65}.[a-z]{3}/;
return reg.test(str);
}
function isMobile(str) {
var reg = /^1\d{10}$/;
return reg.test(str);
}
function register() {
if (!checkemail()) {
return false;
}else if (!checkpass()) {
return false;
}else if (!checkrpass()) {
return false;
}else if(!checkMobile){
return false;
}else{
return true;
}
}
</script>
</head>
<body>
<%@include file="header.jsp" %>
<div class="container">
<div class="row clearfix">
<div class="col-md-3 column">
</div>
<div class="col-md-6 column">
<div class="bg1">
<form class="form-horizontal" role="form" action="/mydemo/servlet/UserServlet?action=register" method="post" onsubmit="return register()">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">邮箱:</label>
<div class="col-sm-10">
<input type="text" class="form-control btt" id="uEmail" name="email"onblur="checkEmail()"/>
<span id="emailts"></span>
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">密码:</label>
<div class="col-sm-10">
<input type="password" class="form-control btt" id="uPass" name="pass"onblur="checkPass()"/>
<span id="passts"></span>
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">确认密码:</label>
<div class="col-sm-10">
<input type="password" class="form-control btt" id="uRPass" onblur="checkRpass()"/>
<span id="passrts"></span>
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">手机:</label>
<div class="col-sm-10">
<input type="text" class="form-control btt" id="tel" name="tel"onblur="checkMobile()"/>
<span id="telts"></span>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default btt bttt" >注册</button>
</div>
</div>
</form>
</div>
</div>
<div class="col-md-3 column">
</div>
</div>
</div>
<%@include file="foot.jsp" %>
</body>
</html>
习惯受伤
相关分类