Ali*_*ahi 5 javascript jquery jquery-select2
select2组件可以配置为接受新值,如在Select2下拉列表中询问但是允许用户使用新值?
你可以在http://jsfiddle.net/pHSdP/646/看到它,代码如下:
$("#tags").select2({
createSearchChoice: function (term, data) {
if ($(data).filter(function () {
return this.text.localeCompare(term) === 0;
}).length === 0) {
return {
id: term,
text: term
};
}
},
multiple: false,
data: [{
id: 0,
text: 'story'
}, {
id: 1,
text: 'bug'
}, {
id: 2,
text: 'task'
}]
});
Run Code Online (Sandbox Code Playgroud)
问题是,如果输入新值并按Enter键或按Tab键,则新值仅添加到列表中.
是否可以将select2组件设置为在使用类型时接受此新值并保留select2.(就像普通的html输入标签一样,通过点击屏幕上的某个位置保留你输入的值)
我发现select2有select2-blur事件,但我找不到获取这个新值并将其添加到列表的方法?!
小智 5
我正在使用Select2 4.0.3,不得不添加两个选项:
tags: true,
selectOnBlur: true,Run Code Online (Sandbox Code Playgroud)
这对我有用
| 归档时间: |
|
| 查看次数: |
15116 次 |
| 最近记录: |