$(function() {
function split(val) {
return val.split(/,\s*/);
}
function extractLast(term) {
return split(term).pop();
}
$("#names").autocomplete({
source: function(request, response) {
$.ajax({ url: "<?php echo site_url('update/suggestions'); ?>",
data: { term: extractLast(request.term)},
dataType: "json",
type: "POST",
success: function(data){
response(data);
},
focus: function() {
// prevent value inserted on focus
return false;
},
select: function(event, ui) {
var terms = split(this.value);
// remove the current input
terms.pop();
// add the selected item
terms.push(ui.item.value);
// add placeholder to get the comma-and-space at the end
terms.push("");
this.value = terms.join(",");
return false;
}
});
},
minLength: 2
});
});
上述代碼正在替換現有選擇,而不是將新選擇添加到現有選擇。這是在Codeigniter中。單個自動填充工作正常。 這不適用於將多個值添加到單個輸入字段的多個輸入字段。多個自動完成不起作用
自動建議停止工作。 –
這是因爲我沒有過濾錯誤處理程序(我的靜態數據源)中的列表。我已經更新了小提琴,現在它正確過濾。 –
你是一個救命不能感謝的人,已經爲此奮鬥了10天。 –