我正在使用JQuery Select2组件(请参阅此处:http://ivaynberg.github.io/select2/),但我在配置它时遇到问题,因此它可以用作双重用途 - 作为匹配数据的自动提示,也可以作为新条目的文本框。有人可以帮我正确配置该组件吗?
答案 0 :(得分:1)
我相信您正在寻找标记选项:
它允许您设置自己的数据以匹配但接受自定义输入。
$("#e20").select2({
tags:["red", "green", "blue"],
tokenSeparators: [",", " "]
});
答案 1 :(得分:1)
代替
$('#name').select2();
您可以尝试使用此功能:
$('#name').select2({
multiple: false,
tags: true,
createTag: function (tag) {
return {id: tag.term, text: tag.term, tag: true};
}
});