zoukankan      html  css  js  c++  java
  • jQuery UI Autocomplete

    jQuery UI Autocomplete 的插件官方文档:http://jqueryui.com/demos/autocomplete/

    jQuery UI Autocomplete 的下载地址:http://jqueryui.com/download

    前台html代码

    View Code
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title>
    <script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
    <script type="text/javascript" src="Scripts/jquery.autocomplete.js"></script>
    <link type="text/css" rel="Stylesheet" href="Styles/jquery.autocomplete.css" />
    <script type="text/javascript">
    $(function () {
    var selector = $("#TextBox1");
    selector.autocomplete(
    {
    minLength: 1,
    source: function (request, response) {
    $.ajax({
    url: "Getdrug.ashx?key=" + encodeURI(selector.val()),
    dataType: "json",
    data: request,
    success: function (data) {
    response(data);
    }
    });
    },
    select: function (event, ui) {
    alert("你选择的是:label:" + ui.item.label + " value:" + ui.item.value);
    selector.val(ui.item.label);
    alert(selector.val());
    return false;
    }

    });
    });


    </script>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </div>
    </form>
    </body>
    </html>

    后台Ajax代码

    View Code
        /// <summary>
    /// Summary description for Getdrug
    /// </summary>
    public class Getdrug : IHttpHandler
    {
    public void ProcessRequest(HttpContext context)
    {
    string key = context.Request.QueryString["key"];
    if (!string.IsNullOrEmpty(key))
    {
    List<Drug> drugs = new List<Drug>();
    drugs.Add(new Drug() { value = 1, label = "yy" });
    drugs.Add(new Drug() { value = 2, label = "xx" });

    drugs = drugs.Where(t => t.label.Contains(key)).ToList();
    string result = Newtonsoft.Json.JsonConvert.SerializeObject(drugs);
    context.Response.ContentType = "text/plain";
    context.Response.Write(result);
    }
    }


    public bool IsReusable
    {
    get
    {
    return false;
    }
    }
    }

    public class Drug
    {
    public int value { get; set; }
    public string label { get; set; }
    }



     

  • 相关阅读:
    Form 中调用指定请求并给定默认参数
    OAF 汇总行的做法
    EBS 开发常用SQL
    EBS 中常用的配置文件及说明
    OAF 常见概念介绍
    OAF 多语言的实现
    OAF 个性化基础
    OAF 开发前置配置
    条款20 STL函数对象
    条款19 command 模式与好莱坞法则
  • 原文地址:https://www.cnblogs.com/50614090/p/2216483.html
Copyright © 2011-2022 走看看