1个回答
展开全部
这是AJAX来实现的,具体代码你可以百度类似“ASP+AJAX实现用户名检测”
参考代码:
user.asp
用户名<input name="UserNameQ" title="请输入用户名" onBlur="RegUserCheck();" ><span id="chekRegName"></span>
<script type="text/javascript">
function RegUserCheck()
{
var xml = new ActiveXObject("MSXML2.XMLHTTP");
username2=document.getElementById("UserNameQ").value;
xml.open("get","RegUsercheck.asp?UserNameQ="+username2+"",true);
xml.send();
if (xml.responseText == 0)
{
document.getElementById('chekRegName').innerHTML="此用户名可以注册";
}
else if (xml.responseText == 1)
{
document.getElementById('chekRegName').innerHTML="此用户已被他人注册,请更换一个再试";
}
else
{
document.getElementById('chekRegName').innerHTML="用户名检测时发生错误";
}
}
</script>
RegUsercheck.asp代码
<!--#include file="Inc/conn.asp"-->
<%
Function codepass()
UserNameQ=request("UserNameQ")
sql="select * from [User] where UserNameQ='"&UserName&"'"
rs.open sql,conn,1,1
If rs.eof Then
codepass = True
Else
codepass = False
End If
rs.close
Set rs=nothing
Set conn=Nothing
End Function
%>
<%
If codepass() then
response.write "1"
else
response.write "0"
end if
%>
参考代码:
user.asp
用户名<input name="UserNameQ" title="请输入用户名" onBlur="RegUserCheck();" ><span id="chekRegName"></span>
<script type="text/javascript">
function RegUserCheck()
{
var xml = new ActiveXObject("MSXML2.XMLHTTP");
username2=document.getElementById("UserNameQ").value;
xml.open("get","RegUsercheck.asp?UserNameQ="+username2+"",true);
xml.send();
if (xml.responseText == 0)
{
document.getElementById('chekRegName').innerHTML="此用户名可以注册";
}
else if (xml.responseText == 1)
{
document.getElementById('chekRegName').innerHTML="此用户已被他人注册,请更换一个再试";
}
else
{
document.getElementById('chekRegName').innerHTML="用户名检测时发生错误";
}
}
</script>
RegUsercheck.asp代码
<!--#include file="Inc/conn.asp"-->
<%
Function codepass()
UserNameQ=request("UserNameQ")
sql="select * from [User] where UserNameQ='"&UserName&"'"
rs.open sql,conn,1,1
If rs.eof Then
codepass = True
Else
codepass = False
End If
rs.close
Set rs=nothing
Set conn=Nothing
End Function
%>
<%
If codepass() then
response.write "1"
else
response.write "0"
end if
%>
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询