jQuery select2在添加标签后立即中断 [英] jQuery select2 breaks as soon as I add tags

查看:65
本文介绍了jQuery select2在添加标签后立即中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将标签添加到jQuery select2中后,它就会中断并恢复为正常的HTML select框.

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();
});

推荐答案

如果您在JavaScript控制台中查看,则会看到以下错误消息:

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

错误:Select2附加到选项卡后,不允许对选项2使用选项标签" <select>元素.

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

这意味着,当您要使用标签"选项时,必须将其应用于input:text元素而不是select.

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: http://jsfiddle.net/Y8Wc7/

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

这篇关于jQuery select2在添加标签后立即中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆