jquery插件autocomplete用法示例
sust2012 人气:0本文实例讲述了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的前台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", //请求的后台路径 { 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 }; //对后台返回的json进行格式转换 } 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 + "结果</td></tr></table>"; return item; //autocomplete提示时的格式 } }).result(function(even,item){ var catalogName=item.catalogName; window.open("productList/fuzzySearch/"+catalogName+"/"+kw+".html?page=1","_blank"); //鼠标点击时的事件 }); }); </script>
(3)后台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; }
希望本文所述对大家jQuery程序设计有所帮助。
加载全部内容