国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > AJAX > 正文

Ajax郵箱、用戶名唯一性驗證實例代碼

2024-09-01 08:27:02
字體:
來源:轉載
供稿:網友

廢話不多說了,直接給大家貼代碼了,具體代碼如下所示:

 <script type="text/javascript">    $(function () {       $("#txtEmail").blur(function () {        $.ajax({          type: "post",          url: "reg.ashx?email=" + $.trim($("#txtEmail").val()) + "&d=" + (+new Date()),          success: function (data) {            var vCount = parseInt(data);            if (vCount == 0) {              alert("郵箱可以使用");            }            else {              alert("郵箱已經被占用");            }          }        });      });      $("#checkpwd").blur(function () {        return CheckPwd();      });    });    function CheckPwd()    {      var bCheck = true;      if ($.trim($("#pwd").val()) != $.trim($("#checkpwd").val()))      {        alert("兩次密碼輸入不一致");        bCheck = false;      }      return bCheck;    }  </script>

reg.ashx代碼:

using System;using System.Collections.Generic;using System.Linq;using System.Web;namespace WebT1.Ti.html2{  /// <summary>  /// reg 的摘要說明  /// </summary>  public class reg : IHttpHandler  {    public void ProcessRequest(HttpContext context)    {      if (context.Request["email"] != null)      {        string strEmail = context.Request["email"];        List<UserModel> lstUser = DataService.GetUserList();        var v = lstUser.Where(p => p.Email == strEmail);        int iCount = 0;        if (v.Count() > 0)        {          iCount = 1;        }        context.Response.ContentType = "text/plain";        context.Response.Write(iCount.ToString());      }    }    public bool IsReusable    {      get      {        return false;      }    }  }  public class DataService  {    /// <summary>    /// 模擬已注冊用戶數據    /// </summary>    public static List<UserModel> GetUserList()    {      var list = new List<UserModel>();      list.Add(new UserModel() { Email = "t1@demo.com" });      list.Add(new UserModel() { Email = "t2@demo.com" });      list.Add(new UserModel() { Email = "t3@demo.com" });      list.Add(new UserModel() { Email = "t4@demo.com" });      list.Add(new UserModel() { Email = "t5@demo.com" });      return list;    }  }  public class UserModel  {    public string Email { get; set; }  }}

總結

以上所述是小編給大家介紹的Ajax郵箱、用戶名唯一性驗證實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對錯新站長站網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 韶山市| 渭南市| 蓬安县| 沅陵县| 信阳市| 历史| 杭州市| 阳西县| 铁力市| 崇明县| 玉门市| 永州市| 白水县| 南木林县| 桓仁| 大连市| 泽州县| 兴文县| 星子县| 富平县| 湖南省| 舟山市| 衡山县| 太保市| 武隆县| 滨州市| 昂仁县| 曲靖市| 和平县| 甘泉县| 哈巴河县| 米易县| 鲁山县| 宁河县| 北京市| 中牟县| 屏东县| 准格尔旗| 阿坝| 霸州市| 马山县|