标签:
1. 实现的方法
1 /* 2 * js实现的文本框的自动完成功能 3 */ 4 function doAutoComplete(textid,dataid,url){ 5 $("#" + textid).autocomplete({ 6 serviceUrl: url, 7 paramName: "name", 8 delimiter: ",", 9 transformResult: function(response) { 10 return { 11 suggestions: $.map($.parseJSON(response), function(item) { 12 return { value: item.tagName, data: item.id }; 13 }) 14 }; 15 }, 16 onSelect: function (suggestion) { 17 $("#" + dataid).val(suggestion.data); 18 } 19 }); 20 };
2. 调用方法
<script src="<c:url value="/scripts/jquery/jquery.1.10.2.min.js" />"></script>
<script src="<c:url value="/scripts/jquery/jquery.autocomplete.min.js" />"></script>
<script src="<c:url value="/scripts/my.js" />"></script>
<script type="text/javascript">
doAutoComplete("userName","userId","${pageContext.request.contextPath}/userform/getUserList");
</script>
附:jquery.autocomplete.js的下载地址
标签:
原文地址:http://www.cnblogs.com/disappearwind/p/4651078.html