1、需引入 jquery-ui-1.12.1.js,jquery-ui-1.12.1.css
2、
var option = {
source: function( request, response ) {
var key = request.term;
if (key.indexOf("'")>-1){
return;
}
if ( key in cache ) {
response( $.map( cache[key], function(item) {
return {
orgCode:item.orgCode,
orgName:item.orgName,
value: item.orgName
};
}));
return;
}
$.ajax({
url: "getOrgTips",
dataType: "json",
type:"POST",
data:{
key: request.term
},
success: function( data ) {
cache[key] = data;
response( $.map(data, function(item) {
return {
orgCode:item.orgCode,
orgName:item.orgName,
value: item.orgName
};
}));
}
});
},
minLength: 1,
delay: 100,
select: function( event, ui ) {
//console.log(ui.item.orgCode+'-'+ui.item.orgName);
$("#repOrg").val(ui.item.orgCode);
$("#orgName").val(ui.item.orgName);
},
focus: function( event, ui ) {
//console.log(ui.item.orgCode+'-'+ui.item.orgName);
$("#repOrg").val(ui.item.orgCode);
$("#orgName").val(ui.item.orgName);
}
};
$("#orgName").autocomplete(option);