jq 搜索自动提示插件
<input value="" name="type" class="ss" id="internalNav_txtsearch" maxlength="20" type="text"> var options = { serviceUrl: '/handler/SearchHandler.ashx?action=search' }; $('#internalNav_txtsearch').autocomplete(options);
服务器端代码
private string GetKeyWord() { string keyword = HDRequestStr("query", ""); IList<searchrecordEN> _r = searchrecordBLL.Instance.GetKeywordCache().Where(s => s.KeyWord.Contains(keyword)&&s.PlatformId==MultiHost.CurrentPlatId).OrderByDescending(s => s.Count).Take(10).ToList(); Dictionary<string, object> _d = new Dictionary<string, object>(); List<string> _k = new List<string>(); foreach (searchrecordEN item in _r) { _k.Add(item.KeyWord); } _d.Add("query", keyword); _d.Add("suggestions", _k); _d.Add("data", _k); return JsonConvert.SerializeObject(_d); }
效果:
![](http://images0.cnblogs.com/blog/335209/201301/07161920-a88bf8bc22f24cbd9995715ffdd6c364.jpg)
下载地址:
www.devbridge.com/projects/autocomplete/jquery