[英]Select2 multiple: true not working
I am using the select2 gem in a rails app, I can not get the form to accept multiple values, I checked the documentation and it seemed straight forward but I can not get it to work.我在 rails 应用程序中使用 select2 gem,我无法让表单接受多个值,我检查了文档,看起来很简单,但我无法让它工作。
<link href="select2.css" rel="stylesheet"/>
<script src="select2.js"></script>
<script>
$(document).ready(function() { $("#e2").select2({
multiple:true
});
});
</script>
<select id="e2">
<option value="AL">Alabama</option>
<option value="WY">Wyoming</option>
</select>
From the docs: "When Select2 is attached to a select element {multiple:true} will be ignored and select's multiple attribute will be used instead."来自文档:“当 Select2 附加到选择元素时,{multiple:true} 将被忽略,而将使用选择的 multiple 属性。”
So this should work:所以这应该有效:
<select multiple id="e2">
<option value="AL">Alabama</option>
<option value="WY">Wyoming</option>
</select>
Example fiddle for multiple select2: http://jsfiddle.net/marcusasplund/sqvLx3qd/多个 select2 的示例小提琴: http : //jsfiddle.net/marcusasplund/sqvLx3qd/
Link to docs: http://ivaynberg.github.io/select2/#documentation链接到文档: http : //ivaynberg.github.io/select2/#documentation
hey this will help you嘿,这会帮助你
<select multiple="multiple" id="e2">
<option value="AL">Alabama</option>
<option value="WY">Wyoming</option>
</select>
<script>
$(document).ready(function() {
$("#e2").select2({
placeholder: "**Put Your Place Holder Here**"
});
});
</script>
<select class="form-control form-control-sm select valid" id="UserTagsFilterValue" multiple="multiple" name="UserTagsFilterValue" aria-invalid="false">
<option value=""></option>
<option value="7">ahahah</option>
<option value="9">tag2</option>
</select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.