Blogger Information
Blog 4
fans 0
comment 0
visits 2791
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
海南湛江七星排五收奖网站系统程序源码出租
一路向北
Original
1351 people have browsed it

海南湛江七星排五收奖网站系统程序源码出租,支持电脑,手机版,功能齐全,稳定,完善 , 扣扣q是3523-6571-33 , 欢迎大来咨询。

使用jQuery给出提示信息

用户注册的时候,使用Ajax实现检测用户名是否已经被注册过,很多细节没有实现,给大家做个简单普及。

<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>用户注册页面</title>
<script src="https://libs.baidu.com/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest(){
if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}else if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
}
}
function validate(account){
createXMLHttpRequest();
xmlHttp.open("Get","ValidateServlet?account="+account,true);
xmlHttp.onreadystatechange = callback;
xmlHttp.send(null);
}
function callback(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
var text = xmlHttp.responseText;
if(text=="true"){
//document.getElementById("msg").innerHTML = "该手机号已经被注册过";
$("#msg").text("该手机号已经被注册");
$("#sub").attr("disabled","true");//添加disabled属性,让按钮不可用
}else{
//document.getElementById("msg").innerHTML = "";
$("#msg").text("");
$("#sub").removeAttr("disabled");//移除disabled属性,让按钮可用

}
}else{
alert("请求失败,错误码="+xmlHttp.status);
}
}
}
function checkInfo(){
var account = $("#account").val();
var pwd1 = $("#pwd1").val();
var pwd2 = $("#pwd2").val();
if(account==""||account==null){
$("#msg").text("账号不能为空");
$("#sub").attr("disabled","true");
return false;
}
if(pwd1==""||pwd1==null||pwd2==""||pwd2==null||pwd1!=pwd2){
$("#info").text("密码不能为空或者两次密码不一致");
$("#sub").attr("disabled","true");
return false;
}
$("#msg").text("");
$("#info").text("");
$("#sub").removeAttr("disabled");
}
function submit(){
checkInfo();
$("#reg").submit();
}

</script>
</head>
<body>
<form id="reg" name="reg" action="RegisterServlet" method="post">
账号:<input type="text" name="account" id="account" onblur="validate(this.value);">
<span id="msg" style="color:red">请输入手机号</span><br>
密码:<input type="password" id="pwd1" name="password1" onblur="checkInfo();"><br>
确认密码:<input type="password" id="pwd2" name="password2" onblur="checkInfo();">
<span id="info" style="color:red"></span><br>
<input type="button" id="sub" value="提交" onclick="submit();">
</form>
</body>
</html>

扣扣q是3523-6571-33 , 欢迎大来咨询。‍

到此这篇关于利用Ajax检测用户名是否被占用的文章就介绍到这了



Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post