jQuery TextBox自动完成条

2022-01-13,,

刚开始学jQuery,于是想试试学习效果,所以就做了个这个TextBox自动完成条,练习练习。请牛人们别笑话。

代码如下:
复制代码 代码如下:

无标题页
<!--
.mouseEnter
{
background-color: Yellow;
}

--> .mouseEnter
{
background-color: Yellow;
}

<table style="width: 100%; border-style: none solid solid solid; border-width: 1px;
border-color: #00FF00">

 

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

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文档内容都是随机产生的:所以下面的效果显示的结果都是随机生成的;不说了。来个图例:

以上就是jQuery TextBox自动完成条的详细内容,更多请关注本站其它相关文章!

《jQuery TextBox自动完成条.doc》

下载本文的Word格式文档,以方便收藏与打印。