• 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; }
    }



     

  • 相关阅读:
    学习WindowsPhone 2013/12/22
    spring-aop学习
    easymock+junit+spring学习·
    javaWeb实现文件上传与下载 (转)
    Java实现视频网站的视频上传、视频转码、视频关键帧抽图, 及视频播放功能
    jsp自定义标签
    listener监听器
    移植一个项目到本地的问题
    struts1拦截器
    eclipse开发 javafx(转)
  • 原文地址:https://www.cnblogs.com/50614090/p/2216483.html
Copyright © 2020-2023  润新知