[英]Tagging text in jquery select2
<select multiple id="e1" style="width:300px">
<option value="AL">Alabama</option>
<option value="Am">Amalapuram</option>
<option value="An">Anakapalli</option>
<option value="Ak">Akkayapalem</option>
<option value="WY">Wyoming</option>
</select>
$("#e1").select2({'placeholder': ' ','allowClear': true});
it is working fine for matched text. 它适用于匹配的文本。 But i want to tag text(which doesnot match any option).
但我想标记文本(与任何选项都不匹配)。 Kindly help.
请帮助。
please find the demo code in following link. 请在以下链接中找到演示代码。 http://jsfiddle.net/marcusasplund/jEADR/2/
http://jsfiddle.net/marcusasplund/jEADR/2/
You have the tags option, but it can't be used with select
element 您有标签选项,但它不能与
select
元素一起使用
$("#e1").select2({ tags: [{ "id": "AL", "text": "Alabama" }, { "id": "Am", "text": "Amalapuram" }, { "id": "An", "text": "Anakapalli" }, { "id": "Ak", "text": "Akkayapalem" }, { "id": "WY", "text": "Wyoming" }] });
<script type="text/javascript" src="//code.jquery.com/jquery-1.8.3.js"></script> <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/select2/3.2/select2.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/select2/3.2/select2.css"/> <input id="e1" style="width:300px" />
There is an option called tags
in select2
which allows you to unmatched text to tags
but there are some problems here. select2
有一个名为tags
的选项,它允许您将不匹配的文本添加到tags
但这里存在一些问题。
tags
option if you are binding select2
plugin on select
. select
上绑定select2
插件,它将不允许您设置tags
选项。 So for this you need to bind select2
on input
. input
上绑定select2
。 Select2
Version 4.0
allows you to add tags
option to select
control too. Select2
Version 4.0
允许您添加tags
选项以select
控件。 So the solution is either you need to upgrade to the latest plugin or you need to bind
select2
oninput
control.因此,解决方案是您需要升级到最新的插件,或者您需要在
input
控件上绑定select2
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.