下面是一款完整的用戶在注冊前的ajax驗證用戶名的實現代碼,只要按要求保存就可以了。
下面是一款完整的用戶在注冊前的ajax驗證用戶名的實現代碼,只要按要求保存就可以了。
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>ajax用戶驗證</title>
<style>
body {
font: 12px , arial, helvetica, sans-serif; color: #808080
}
#reg{
width: 600px;
border: 1px dotted #336699;
}
td{font-size:12px;color:}
h1{
height:35px;
font-size:16px;
color:#ffffff;
background-color: #336699;
line-height: 30px;
padding-left:25px;
}.anniu {
border-right: #666666 1px solid; padding-right: 1px; border-top: #ffffff 1px solid; padding-left: 1px; font-size: 9pt; padding-bottom: 1px; border-left: #ffffff 1px solid; cursor: hand; color: #333333; padding-top: 1px; border-bottom: #666666 1px solid; font-family: "宋體"; height: 20px; background-color: #eeeeee
}
.framedivpass{
border: 1px solid #6fbe44;
padding: 2px;
height: 100%;
float: left;
}
.framedivwarn{
border: 1px solid #ff0000;
padding: 2px;
height: 100%;
float: left;
}
</style>
<script language="網頁特效" type="text/javascript">
var xmlhttp = false;
try {
xmlhttp = new activexobject("msxml2.xmlhttp");
} catch (e) {
try {
xmlhttp = new activexobject("microsoft.xmlhttp");
} catch (e2) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof xmlhttprequest != 'undefined') {
xmlhttp = new xmlhttprequest();
}
function ajax(data){
xmlhttp.open("get","user_ck.php教程?username="+document.getelementbyid("username").value,true);
xmlhttp.send(null);
document.getelementbyid('username_notice').innerhtml = process_request;//顯示狀態
xmlhttp.onreadystatechange=function(){
if (4==xmlhttp.readystate){
if (200==xmlhttp.status){
var responsetext = xmlhttp.responsetext;
if (responsetext=="true" ){
ck_user("true");
}
else{
ck_user("false");
}
}else{
alert("發生錯誤!");
}
}
}
}
function chkusername(obj){
if (checks(obj.value)== false)
{
obj.classname = "framedivwarn";
showinfo("username_notice",msg_un_format);
change_submit("true");
}
else if(obj.value.length<1){
obj.classname = "framedivwarn";
showinfo("username_notice",msg_un_blank);
change_submit("true");
}else if(obj.value.length<3){
obj.classname = "framedivwarn";
showinfo("username_notice",username_shorter);
change_submit("true");
}
else{
//調用ajax函數,向服務器端發送查詢
ajax(obj.value);
}}
1 2 3