我正在尝试通过 jquery 自动完成插件实现自动完成。一个简单的自动完成适合我。我无法实现逗号分隔自动完成。
请帮我解决我哪里出错了。
我的jquery代码:
$(document).ready(function() {
$.getJSON('/releases/new.json', function() {
alert("inside getJson");
alert(data1);
$('#release_tester_tokens').autocomplete({source:names,multiple: true});
});
});
谢谢, 拉姆亚。
最佳答案
看看这个 walk-through有帮助。它包含以下代码,允许用户输入用逗号分隔的多个搜索词:
$("#<%= txtMultipleName.ClientID %>").autocomplete({
source: function (request, response) {
$.getJSON("AutoComplete.ashx", {
term: extractLast(request.term)
}, response);
},
search: function () {
// custom minLength
var term = extractLast(this.value);
if (term.length < 1) {
return false;
}
},
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;
}
});
function split(val) {
return val.split(/,\s*/);
}
function extractLast(term) {
return split(term).pop();
}
关于jQuery UI autocomplete也有很多信息。页。
关于jquery - 逗号分隔的自动完成与 jquery 自动完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8716811/