本文實(shí)例講述了jquery插件autocomplete用法。分享給大家供大家參考,具體如下:
(1)引入js和樣式
<script type="text/JavaScript" src="../js/jQuery-1.8.0.js"charset="utf-8"></script><script type="text/javascript" src="../js/jquery.autocomplete.js"charset="utf-8"></script><link href="css/jquery.autocomplete.css" rel="Stylesheet">
(2)autocomplete的前臺(tái)js
<script type="text/javascript">//alert("test");../search/fuzzy/pkword.html$(document).ready(function() {var kw ="";$("#kw").blur(function (){kw = $("#kw").val();});$("#kw").autocomplete("search/fuzzy/pkword.html",//請(qǐng)求的后臺(tái)路徑{parse : function(jsonData) {var parsed = [];for ( var i = 0; i < jsonData.length; i++) {parsed[parsed.length++] = {data : jsonData[i],value : jsonData[i].catalogName,result : jsonData[i].catalogName};//對(duì)后臺(tái)返回的json進(jìn)行格式轉(zhuǎn)換}return parsed;},formatItem : function(row,i,max) {var item = "<table id='auto"+ i+ "'class='a' style='width:100%;'> <tr><td align='left'>在<font color='red'>"+ row.catalogName+ "</font>分類中搜索</td><td align='right' style='color:green;'>約"+ row.catalogCount+ "結(jié)果</td></tr></table>";return item;//autocomplete提示時(shí)的格式}}).result(function(even,item){var catalogName=item.catalogName;window.open("productList/fuzzySearch/"+catalogName+"/"+kw+".html?page=1","_blank");//鼠標(biāo)點(diǎn)擊時(shí)的事件});});</script>
(3)后臺(tái)json用springmvc返回
@ResponseBody@RequestMapping(value = "/search/fuzzy/pkword.html", method = RequestMethod.GET)public List<CatalogCountBean> fuzzySearch(@RequestParam String q) {List<CatalogCountBean> list = null;System.out.println("q:" + q);list = (List<CatalogCountBean>) productListService.fuzzySearch(productListNamespace, q);return list;}
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery拖拽特效與技巧總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jquery中Ajax用法總結(jié)》、《jQuery常見經(jīng)典特效匯總》、《jQuery動(dòng)畫與特效用法總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注