首先页面中代码
<script type="text/javascript" language="javascript" >
var xmlHttp = null;
function CheckUser()
{
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(err1)
{
try
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(err2)
{
xmlHttp = new XMLHttpRequest();
}
}
var Text1 = document.getElementById("Text1");
var url = "chkuser.aspx?User=" + Text1.value;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange = OnHandler;
xmlHttp.send(null);
}
function OnHandler()
{
if(xmlHttp.readyState == 4)
{
var isValid = xmlHttp.responseText;
var exists = document.getElementById("exsits");
exists.innerHTML = isValid.substring(0,4);
}
}
</script >
<input id="Text1" type="text" onblur="CheckUser()" / > <label d="exsits" > </label > <br / >
然后建一个chkuser.aspx,其后台代码改为
protected void Page_Load(object sender, EventArgs e)
{
string user = this.Request.QueryString["User"];
if (UserExist(user))
{
Response.Write("存在");
}
else
{
Response.Write("不存在");
}
}
private bool UserExist(string username)
{
ClassLib.Employee emp = new ClassLib.Employee();
return emp.EmpNameExist(username);
}
就可以了
注:最后面的那个函数要改一下