如何在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:/中的页面示例中那样在输入中插入默认值. /Tagyn支持中的/ivaynberg.github.io/select2/,输入的默认值为'brown','red'和& 绿色".
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屋!