ajax + jquery 实现自动完成autocomplete
-
<script???src=
"${pageContext.request.contextPath}/js/jquery-1.5.1.js"
>??
-
</script>??
-
????????<script?type="text/javascript"
??
-
????????????src="${pageContext.request.contextPath}/js/jquery-ui-1.8.13.custom.min.js"
>??
-
</script>??
-
????????<link?rel="stylesheet"
?type=
"text/css"
??
-
????????????href="${pageContext.request.contextPath}/css/jquery-ui-1.8.13.custom.css"
?/>??
代码实现
-
<script?type=
"text/javascript"
>??
-
var
?nameDate?=?
""
;??
-
function
?onLoadMsg()?{??
-
???$("#cusName"
).autocomplete(?{??
-
????????autoFill?:?false
,??
-
????????matchContains:?true
,??
-
????????source?:?nameDate??
-
????});??
-
????var
?cusName?=?$(
"#cusName"
).val();??
-
????jQuery.post("customer_nameSelect?cusName="
?+?cusName,?
function
(data)?{??
-
????????nameDate?=?data;??
-
????});??
-
??????
-
??????
-
}??
-
function
?onShow(){??
-
}??
-
$().ready(function
()?{??
-
});??
-
</script>??
页面文件触发
-
<input?type=
"text"
?id=
"cusName"
?name=
"entity.customners.id"
??
-
????????????????????????????????????????onkeypress="onLoadMsg()"
?onkeyup=
"onShow()"
>??
效果图