本文实例讲述了JS实现仿google、百度搜索框输入信息智能提示的实现方法。分享给大家供大家参考。具体如下:
仿google、百度搜索框输入信息智能提示的实现
服务器端C#代码
<%@ WebHandler Language="C#" Class="SearchResult" %> using System; using System.Web; using System.Data; public class SearchResult : IHttpHandler { public void ProcessRequest (HttpContext context) { object QueryWord=context.Request.QueryString["searchText"]; if (QueryWord != null) { if (QueryWord.ToString().Trim().Length > 0) { DataTable dt = getDB(); string returnText = ""; if (dt != null && dt.Rows.Count > 0) { DataRow[] dr = dt.Select(" name like '%" + QueryWord .ToString()+ "%' "); if (dr.Length > 0) { for (int i = 0; i < dr.Length; i++) { //可设置返回多字符串 returnText += dr[i]["id"].ToString() + "@" + dr[i]["name"].ToString() + "\n"; } } } context.Response.Write(returnText); context.Response.End(); } } } public bool IsReusable { get { return false; } } ////// 获取数据源的方法 /// ///数据源 private DataTable getDB() { DataTable dt = new DataTable(); dt.Columns.Add("id"); dt.Columns.Add("name"); dt.Columns.Add("age"); dt.Rows.Add(new object[] { "000001", "张三", "26" }); dt.Rows.Add(new object[] { "000002", "张晓", "26" }); dt.Rows.Add(new object[] { "000003", "张岚", "27" }); dt.Rows.Add(new object[] { "000004", "李四", "25" }); dt.Rows.Add(new object[] { "000005", "李星", "27" }); return dt; } }
希望本文所述对大家的javascript程序设计有所帮助。