Home  >  Article  >  Web Front-end  >  jQuery TextBox autocomplete bar_jquery

jQuery TextBox autocomplete bar_jquery

WBOY
WBOYOriginal
2016-05-16 18:49:331087browse

代码如下:

复制代码 代码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>




无标题页












 






Ajax调用的一般处理程序为:
复制代码 代码如下:

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

using System;
using System.Web;
using System.Linq;
using System.Xml;
using System.Xml.Linq;

public class Suggest : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
HttpResponse Response = context.Response;
Response.Charset = "gb2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "text/plain";
Response.StatusCode = 200;
string start = context.Request.Params["word"].ToString();
Response.Write(GetSuggest(start));
Response.Flush();
}

public bool IsReusable
{
get
{
return false;
}
}

///
/// 获取响应字符串
///

/// 查询起始字符串
/// 响应字符串
private string GetSuggest(string start)
{
XElement root = XElement.Load(AppDomain.CurrentDomain.SetupInformation.ApplicationBase "Suggest.xml");
System.Collections.Generic.IEnumerable
q = (from r in root.Elements()
where (r.Name).ToString().ToLower().StartsWith(start.ToLower())
select r.Name.ToString()).Take(5);
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (string w in q)
{
sb.Append(w ";");
}
if (sb.Length != 0)
sb.Remove(sb.Length - 1, 1);
return sb.ToString();
}

}

其中xml文档其实也不是什么标准的xml文档,就是拿来存储数据,练习练习刚学的Linq to XML。由于不想建表,本人也许有点懒惰吧,xml文档内容都是随机产生的:所以下面的效果显示的结果都是随机生成的;不说了。来个图例:
图例
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn