日期:2014-05-16  浏览次数:20652 次

ajax + jquery 实现自动完成autocomplete
Code:
  1. <script???src= "${pageContext.request.contextPath}/js/jquery-1.5.1.js" >??
  2. </script>??
  3. ????????<script?type="text/javascript" ??
  4. ????????????src="${pageContext.request.contextPath}/js/jquery-ui-1.8.13.custom.min.js" >??
  5. </script>??
  6. ????????<link?rel="stylesheet" ?type= "text/css" ??
  7. ????????????href="${pageContext.request.contextPath}/css/jquery-ui-1.8.13.custom.css" ?/>??

代码实现

Code:
  1. <script?type= "text/javascript" >??
  2. var ?nameDate?=? "" ;??
  3. function ?onLoadMsg()?{??
  4. ???$("#cusName" ).autocomplete(?{??
  5. ????????autoFill?:?false ,??
  6. ????????matchContains:?true ,??
  7. ????????source?:?nameDate??
  8. ????});??
  9. ????var ?cusName?=?$( "#cusName" ).val();??
  10. ????jQuery.post("customer_nameSelect?cusName=" ?+?cusName,? function (data)?{??
  11. ????????nameDate?=?data;??
  12. ????});??
  13. ??????
  14. ??????
  15. }??
  16. function ?onShow(){??
  17. }??
  18. $().ready(function ()?{??
  19. });??
  20. </script>??

页面文件触发

Code:
  1. <input?type= "text" ?id= "cusName" ?name= "entity.customners.id" ??
  2. ????????????????????????????????????????onkeypress="onLoadMsg()" ?onkeyup= "onShow()" >??

效果图