jquery.autocomplete的简单应用

autocomplete非常简单的应用
1、引入文件
jquery.autocomplete.js和jquery.autocomplete.css
2、页面js
$(document).ready(function() {
 var websites ="中 国 我的 未来".split(" ");
     $.ajax({
     url:"<%=request.getContextPath()%>/lgdj.do?method=autoList",
     type:"POST",
     dataType:"script",
     async:false,
     cache:false,
     success:function(data){
   tt=data;
      }
     })
    websites=tt.split(",");
    $('#titlefirst').autocomplete(websites,{ matchContains:true});
})

<input type="text" name="title" id="titlefirst" value=" ">


3、action
public void autoList (HttpServletRequest request,HttpServletResponse response) throws Exception {
  String   title=ServletRequestUtils.getStringParameter(request, "title", "");
  List<PeriodicalManuscript> list=this.lgdjService.autoList(title.trim());
  logger.info("======"+title);
  String str="";
  for (int i = 0; i < list.size(); i++) {
   str+=list.get(i).getTitle()+",";
  }
  // JSONArray obj = JSONArray.fromObject(list);
  PrintWriter out = response.getWriter();
  out.println(str.toString());
  logger.info(str.toString());
  
 }

 

 

你可能感兴趣的:(autocomplete)