我在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>
答案 0 :(得分:3)
来自文档: “当Select2附加到选择元素时{multiple:true}将被忽略,并且将使用select的multiple属性。”
所以这应该有效:
<select multiple id="e2">
<option value="AL">Alabama</option>
<option value="WY">Wyoming</option>
</select>
多个select2的示例小提琴: http://jsfiddle.net/marcusasplund/sqvLx3qd/
答案 1 :(得分:2)
<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>