jQuery select2 breaks as soon as I add tags

纵然是瞬间 提交于 2019-12-07 06:06:02

问题


As soon as I add tags to my jQuery select2 it breaks and reverts back to the normal HTML select box.

Here is my code (exactly like this example):

$(document).ready(function() {
    $("#tags").select2({tags:["red", "green", "blue"]});
});

If I remove the tags part it works again:

$(document).ready(function() {
    $("#tags").select2();
});

回答1:


If you look in your javascript console you will see the following error message:

Error: Option 'tags' is not allowed for Select2 when attached to a <select> element.

That means, when you want to use the 'tags' option, you have to apply it to an input:text element instead of a select.

JSFiddle with proof: http://jsfiddle.net/Y8Wc7/




回答2:


Select2 version 4.0.0 now allows tags to be attached to a <select>



来源:https://stackoverflow.com/questions/24146954/jquery-select2-breaks-as-soon-as-i-add-tags

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!