前台:
function yz2() {
var username = $("#TextBox1").val();
$.ajax({
type: "POST",
url: "UserAdd.aspx?action=ajax",
data: "username=" + username,
success: function (msg) {
// alert(msg);
$("#TextBox1").after("<div id='msg'>"+msg+"</div>");//在文本框后面显示
if (msg.indexOf("用户名已经存在") > -1) {
//判断按钮是否可用
$("#Button1").attr("disabled", true);
}
else {
$("#Button1").attr("disabled", false);
}
}
});
$('#msg').remove();
return true;
}
后台:
if(!String.IsNullOrEmpty(Request ["action"])&& Request["action"]=="ajax")
{
string username = Request["username"];
TextBox1.Attributes.Add("onblur", "return yz2()");