当前位置:编程学习 > C#/ASP.NET >>

在一个文本框中输入名字点击回车键,在证号,地址等文本框中自动填入数据库中对应的数据。

在一个文本框中输入名字点击回车键,在证号,地址等文本框中自动填入数据库中对应的数据。
很急,请问该这么弄? --------------------编程问答-------------------- 捕获文本框的回车事件keydown,在里面写读取数据库,给证号,文本框赋值操作 --------------------编程问答-------------------- 具体怎么弄?好像还需要AJAX无刷新来弄 --------------------编程问答--------------------
引用 1 楼  的回复:
捕获文本框的回车事件keydown,在里面写读取数据库,给证号,文本框赋值操作
具体怎么弄?好像还需要AJAX无刷新来弄 --------------------编程问答-------------------- html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">       

        $().ready(function () {

            $("#xm").bind('keyup', function (event) {
                if (event.keyCode == 13) {
                    $.ajax({
                        url: "Handler3.ashx?xm=" + $("#xm").val(),
                        type: 'POST',
                        dataType: 'text',

                        success: function (data, textStatus) {
                            var list=data.split("***||***"); ;

                            $("#gh").val(list[0]);
                            $("#dz").val(list[1]);
                        },
                        complete: function (XMLHttpRequest, textStatus) {

                        },
                        error: function (error) {
                            ///请求出错处理              
                            alert('错误信息:' + error.status);
                        }
                    });


                }
            });
        });
    
    </script>
</head>
<body>
    <div style="width: 100px; float: left">
        姓名</div>
    <div style="width: 200px; float: left">
        <input id="xm" type="text" /></div>
    <div style="width: 100px; float: left">
        工号</div>
    <div style="width: 200px; float: left">
        <input id="gh" type="text" /></div>
    <div style="width: 100px; float: left">
        地址</div>
    <div style="width: 200px; float: left">
        <input id="dz" type="text" /></div>
</body>
</html>
--------------------编程问答-------------------- handler

<%@ WebHandler Language="C#" Class="Handler3" %>

using System;
using System.Web;

public class Handler3 : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        context.Response.Buffer = true;
        context.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
        context.Response.AddHeader("pragma", "no-cache");
        context.Response.AddHeader("cache-control", "");
        context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
        context.Response.CacheControl = "no-cache";
        
        
        if(context.Request.QueryString["xm"]==null)
            context.Response.Write("");

        if (context.Request.QueryString["xm"].ToString() != "zhangsan")
            context.Response.Write("");
        
        
        
        context.Response.Write("gh123456***||***IUnKnowadress");
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

} --------------------编程问答-------------------- $(document).keydown(function(e){
if(e.keyCode==13)
{
   var name=$.trim($("#你的名称文本框ID").val());
   if(name.length>0)
   {
      var sendData="v="+name;
      $.post("/你的后台操作页面.aspx",sendData,function(data){
          if(data!="0")
          {
             var jsonData = eval("("+data+")");
             $("#你的证号文本框").val(jsonData.CardID);
             $("#你的地址文本框").val(jsonData.Address);
          }
      });
   }
}
});


你的后台操作页面.aspx,输出你拼装的JSON数据即可
Response.Write("Your JSON Data"); --------------------编程问答--------------------
引用 6 楼  的回复:
$(document).keydown(function(e){
if(e.keyCode==13)
{
  var name=$.trim($("#你的名称文本框ID").val());
  if(name.length>0)
  {
  var sendData="v="+name;
  $.post("/你的后台操作页面.aspx",sendData,function(data……

需要在这样的框架下 --------------------编程问答-------------------- 需要在这样的框架下
引用 5 楼  的回复:
handler

<%@ WebHandler Language="C#" Class="Handler3" %>

using System;
using System.Web;

public class Handler3 : IHttpHandler {
   
  public void ProcessRequest (HttpContext context) {
  ……
--------------------编程问答--------------------
引用 4 楼  的回复:
html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title></title>……

需要在这样的框架下 --------------------编程问答-------------------- $(document).ready(function () {
            var txtTextBox = $("#<%=txtVal.ClientID %>");
            txtTextBox.keydown(function (e) {
                if (e.keyCode == 13) {
                    e.keyCode = 9;
                    __doPostBack('lbtnSubimt', '');
                    if (e && e.stopPropagation)
                    //因此它支持W3C的stopPropagation()方法
                        e.stopPropagation();
                    else
                    //否则,我们需要使用IE的方式来取消事件冒泡 
                        window.event.cancelBubble = true;
                    return false;

                }
            });

        }); --------------------编程问答-------------------- 这是什么框架啊,学学 --------------------编程问答-------------------- 这是传说中的ExtJS。
话说程序是不是你写的? --------------------编程问答-------------------- ExtJs啊,话说不是1.3以上要收费吗
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,