龙空技术网

录入时检测数据是否存在的验证

洞悉科学 64

前言:

今天你们对“jquery中判断check”大概比较珍视,大家都需要剖析一些“jquery中判断check”的相关内容。那么小编在网络上收集了一些关于“jquery中判断check””的相关文章,希望小伙伴们能喜欢,我们一起来了解一下吧!

实现:无输入时,提示需要录入;重复时,提示已经存在。

一、数据库知识准备

--查找重复记录,重复记录是根据单个字段(bqid)来判断  select * from banqi where bqid in  (select bqid from banqi group by bqid having COUNT(bqid)>1)​--统计指定bqid的记录数  select COUNT(1) from banqi where bqid='333222'

二、代码

1、表单

<asp:TextBox ID="txtBqid"  lay-verify="title" autocomplete="off" class="layui-input" runat="server" onblur="checkbqid()"></asp:TextBox><span  id="remind"></span>

2、Jquery

        function checkbqid() {            var bqid = $("#txtBqid").val();            if (bqid == "") { alert("请输入5位数班期ID"); return; }            $.ajax({                type: 'get',                url: 'bqidcheck.ashx',                contentType: "application/json;charset=utf-8",                dataType: "text",                data: {bqid: bqid},                success: function (data) {                    $("#remind").html("<font color=red>已经存在,请重新输入!</font>"); $("#txtBqid").focus();                },                error: function () {                    $("#remind").html("<font color=green>用户名可用</font>");                }            });        }

3、ashx

string bqid = context.Request.QueryString["bqid"];bool result = new DAL.banqi().Exists(bqid);context.Response.ContentType = "text/plain";context.Response.Write(result);

4、DAL

       //检测bqid是否存在        public bool Exists(string bqid)        {            StringBuilder strSql = new StringBuilder();            strSql.Append("select  count(1) from banqi");            strSql.Append(" where bqid=@bqid");            SqlParameter[] parameters = {                    new SqlParameter("@bqid",SqlDbType.NVarChar,20)};            parameters[0].Value = bqid;            int res= new SqlHelper().ExecuteNonQuery(strSql.ToString(), parameters, CommandType.Text);            if (res > 0)            {                return true;            }            else            {                return false;            }        }

标签: #jquery中判断check