jquery插件autocomplete用法示例
本文实例讲述了jquery插件autocomplete用法。分享给大家供大家参考,具体如下:
(1)引入js和样式
<scripttype="text/JavaScript"src="../js/jQuery-1.8.0.js" charset="utf-8"></script> <scripttype="text/javascript"src="../js/jquery.autocomplete.js" charset="utf-8"></script> <linkhref="css/jquery.autocomplete.css"rel="Stylesheet">
(2)autocomplete的前台js
<scripttype="text/javascript"> //alert("test");../search/fuzzy/pkword.html $(document).ready(function(){ varkw=""; $("#kw").blur(function(){ kw=$("#kw").val(); }); $("#kw").autocomplete("search/fuzzy/pkword.html", //请求的后台路径 { parse:function(jsonData){ varparsed=[]; for(vari=0;i<jsonData.length;i++){ parsed[parsed.length++]={ data:jsonData[i], value:jsonData[i].catalogName, result:jsonData[i].catalogName }; //对后台返回的json进行格式转换 } returnparsed; }, formatItem:function(row,i,max){ varitem="<tableid='auto" +i +"'class='a'style='width:100%;'><tr><tdalign='left'>在<fontcolor='red'>" +row.catalogName +"</font>分类中搜索</td><tdalign='right'style='color:green;'>约" +row.catalogCount +"结果</td></tr></table>"; returnitem; //autocomplete提示时的格式 } }).result(function(even,item){ varcatalogName=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) publicList<CatalogCountBean>fuzzySearch(@RequestParamStringq){ List<CatalogCountBean>list=null; System.out.println("q:"+q); list=(List<CatalogCountBean>)productListService.fuzzySearch( productListNamespace,q); returnlist; }
更多关于jQuery相关内容感兴趣的读者可查看本站专题:《jQuery扩展技巧总结》、《jQuery常用插件及用法总结》、《jQuery拖拽特效与技巧总结》、《jQuery表格(table)操作技巧汇总》、《jquery中Ajax用法总结》、《jQuery常见经典特效汇总》、《jQuery动画与特效用法总结》及《jquery选择器用法总结》
希望本文所述对大家jQuery程序设计有所帮助。