<script type="text/javascript">
$(function(){
$("#name").blur(function(){
$("#na").empty();
name=$("#name").val();
if($("#name").val()==""){
var span=$("<span id='na'>用户名不能为空</span>");
$("#name").after(span);
}else{
sname=true;
}
});
$("#password").blur(function(){
$("#pass").empty();
password=$("#password").val();
if($("#password").val()==""){
var span=$("<span id='pass'>密码不能为空</span>");
$("#password").after(span);
}else{
spassword=true;
}
});
$("#email").blur(function(){
$("#ema").empty();
email=$("#email").val();
regemail=/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
if($("#email").val()==""){
var span=$("<span id='ema'>邮箱不能为空</span>");
$("#email").after(span);
}else if(!regemail.test(email)){
var span=$("<span id='ema'>邮箱格式不对,如:123456@qq.com</span>");
$("#email").after(span);
}else{
semail=true;
}
});
$("#bu").click(function(){
if(sname&&spassword&&semail){
$.post("${pageContext.request.contextPath }/user/insertUser",{"name":name,"password":password,"email":email},function(d){
if(d=="ok"){
alert("添加成功,三秒跳转登录界面......");
window.setTimeout("location.href='${pageContext.request.contextPath }/login.jsp';",3000);
}else{
alert("添加失败");
}
},"json");
}
});
});
</script>
<body>
<center>
<h1>注册页面</h1>
<form action="addUser.do">
用户名<input type="text" name="name" id="name"><br>
密码<input type="password" name="password" id="password"><br>
邮箱<input type="text" name="email" id="email"><br>
<input type="button" value="提交" id="bu">
</form>
</center>
</body>
SSM---之JQuery验证
最新推荐文章于 2020-02-01 17:45:42 发布