首先导入css和js两个包
jQuery("#project_name").autocomplete("${pageContext.request.contextPath}/wechat/inquiry/autoComplete.shtml", {
width : $("#project_name").css("width"), // 提示的宽度,溢出隐藏
/* max : 10,// 显示数量 */
autoFill : false,
scroll : false, // 当结果集大于默认高度时是否使用卷轴显示
highlight : false,
highlightItem: true,
scroll : true,
matchContains : true,
multiple :false,
formatItem: function(row, i, max) {
items = "name";
var address=row.address!=null?('['+row.address+']'):'';
return '<span style="color:gray;padding-right:10px;"> ' + row.name + '</span> <span style="color:#005EA7">' + address + '</span>';
},
formatMatch: function(row, i, max) {
return row.name;
},
formatResult: function(row) {
return row.name;
},
parse:function(data) {//解释返回的数据,把其存在数组里
var array=eval(data);
var parsed = [];
if(array == null) {
return parsed;
}
for (var i = 0; i < array.length; i++) {
parsed[i] = {
data: array[i],
result: array[i].name
};
}
return parsed;
}
}).result(function(event, row, formatted) {
var city=row.city!=null?(row.city):'';
var district=row.district!=null?(row.district):'';
var section=row.section!=null?(row.section):'';
var address=row.address!=null?(row.address):'';
jQuery(this).val(row.name);
$("#project_address").val(city+"市"+district+"区"+section+address);
});
<div class="yf_pr_box_text">
<div class="title-text" ><font style="color:red">*</font>楼盘名称:</div>
<div style=" position:relative;">
<input id="project_name" name="EvaObjectFormMap.name" type="text" autocomplete="off" value="${obj.name}"
placeholder=" 请输楼盘名称" class="obj objreq yf_or_xlk_t_pr_inq" style="background:#fff8f0;" tipPosition="bottom">
</div>
</div>