如何在select2 jquery中的标记中设置默认值 [英] How to set Default Value in tagging in select2 jquery
问题描述
我正在使用 select2 (http://ivaynberg.github.io/select2/)我的标签输入.从使用 select2 标记的示例中,代码如下所示.
I am using select2 (http://ivaynberg.github.io/select2/) for my tagging input. from the example in using select2 tagging the code is look like this.
$("#e12").select2({tags:["red", "green", "blue"]});
现在我的问题是如何在我的输入中插入默认值,就像在 http:/中的页面示例中一样/ivaynberg.github.io/select2/ 在标记支持中,输入的默认值为棕色"、红色"和 &'绿色'.
now my problem is how can I insert default value in my input just like in the page example in http://ivaynberg.github.io/select2/ at Tagging Support, the input has a default value of 'brown', 'red', & 'green'.
推荐答案
您可以通过为隐藏输入提供值来初始化 Select2 控件:
You can initialize the Select2 control by providing a value for the hidden input:
<input type="hidden" id="e12" value="brown,red,green" />
您可以通过将数组传递给 'val' 方法来设置 Select2 控件的值:
And you can set the value of the Select2 control by passing an array to the 'val' method:
$('#tagSelect').select2('val', ['brown','red','green']);
这篇关于如何在select2 jquery中的标记中设置默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!