【发布时间】:2015-12-18 04:43:19
【问题描述】:
我正在使用自动完成 Web 服务 sing JSON,如果我选择的列表项不能再次出现在自动完成列表中;
JSON AJAX 代码:
select: function (event, ui) {
var terms = split(this.value);
if (terms.length <= 10) {
// 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;
}
else {
var last = terms.pop();
$(this).val(this.value.substr(0, this.value.length - last.length - 0)); // removes text from input
$(this).effect("highlight", {}, 1000);
$(this).addClass("red");
$("#warnings").html("<span style='color:red;'>Max skill reached</span>");
return false;
}
}
【问题讨论】:
-
你能提供一个jsfiddle,或者至少更多的代码(html等)
-
介意我问为什么?如果用户删除它,它是否必须回到列表中?
-
@Bindrid,我不知道你在问什么,你的问题对我来说是有线的。对不起
-
@Fraser,这里的fiddlr代码:fiddlr Link
-
从选项列表中删除所选项目并不常见,所以我想知道您为什么会这样。顺便说一句,有一个名为 select2 插件的插件可以完成很多我认为您正在尝试做的事情。
标签: json web-services jquery-ui asp.net-ajax jquery-autocomplete