看起來這應該幫助你。
這是基於官方jqueryui autocomplete example,我對最相關的部分稍加評論:
$("#tags").autocomplete({
source: function(request, response) {
// use only the string after "(" to compare against the example array.
response($.ui.autocomplete.filter(availableTags, request.term.slice(request.term.indexOf("(") + 1)));
},
search: function(event, ui) {
var input = event.target.value;
// don't trigger autocomplete until "(" is present.
if(input.indexOf('(') !== -1) {
return true;
}
return false;
},
select: function(event, ui) {
var input = event.target.value;
// return the inputted string + selected value, instead of just selected value alone
ui.item.value = [input.slice(0, input.indexOf("(") + 1), ui.item.label].join("");
}
});
非常感謝,很大的幫助! –