代码如下:
//检测用户名是否被占用
function GetO(){
var ajax=false;
try {
ajax = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
ajax = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
ajax = false;
}
}
if (!ajax && typeof XMLHttpRequest!='undefined') {
ajax = new XMLHttpRequest();
}
return ajax;
}
function getResult(serverPage) {
var ajax = GetO();
var sep = (-1 < serverPage.indexOf("?")) ? "&" : "?"
var newurl = serverPage + sep + "__=" + encodeURIComponent((new Date()).toString());
ajax.open("GET", newurl, true);
ajax.onreadystatechange = function() {
if (ajax.readyState == 4 && ajax.status == 200) {
if(ajax.responseText==1){
ShowResult(1,"您的用户名可以正常注册")
AjaxResult=true;
}else{
ShowResult(0,"您的用户名被占用了")
AjaxResult=false;
}
}
}
ajax.send(null);
}
function chkUsername(){
var sflag;//标记;
var sErr;//错误信息;
sflag=true;
var re=/^/w{2,20}$/;
if(!re.test(document.Form1.UserName.value)){
sflag=false;
sErr="用户名只能输入字母、数字或下划线";
}
if (document.Form1.UserName.value.length>20||document.Form1.UserName.value.length<2){
sflag=false;
sErr="用户名长度必须在2~20个字符之间";
}
if (document.Form1.UserName.value=="" ){
sErr="用户名不能为空";
sflag=false;
}
//ajax检测返回结果
if (!sflag) {
ShowResult(0,sErr)
}else{
getResult("../MemberCheck.aspx?t=1&Name=" + document.Form1.UserName.value);
}
//document.getElementById("spname").innerHTML=ss;
}
function ShowResult(tag,str){
var obj = document.getElementById("spname");
if(tag==0){
obj.style.border="1px solid red";
obj.style.color="red";
}else{
obj.style.border="1px solid green";
obj.style.color="green";
}
obj.innerHTML=str;
obj.style.padding="1px";
}
//取ajax返回的用户问题值
function getQuestionData(sPage){
var ajax = GetO();
var sep = (-1 < sPage.indexOf("?")) ? "&" : "?"
var newurl = sPage + sep + "__=" + encodeURIComponent((new Date()).toString());
ajax.open("GET", newurl, true);
ajax.onreadystatechange = function() {
if (ajax.readyState == 4 && ajax.status == 200) {
if(ajax.responseText==""){
document.getElementById("getstate").innerHTML="用户不存在!"
}
else{
document.g.Question.value=ajax.responseText;
document.g.Question.readOnly=true;
document.getElementById("getpwdstep1").style.display="none";
document.getElementById("getpwdstep2").style.display="block";
document.getElementById("getstate").innerHTML="";
}
}
}
ajax.send(null);
}
function getUserQ(){
//改变报错span的显示样式
document.getElementById("getstate").style.padding="1px 4px";
if (document.g.UserName.value==""){
document.getElementById("getstate").innerHTML="用户名不能为空!"
新闻热点
疑难解答
图片精选