Select2 multiple:true不起作用

时间:2014-05-19 15:03:43

标签: jquery ruby-on-rails jquery-select2

我在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>

2 个答案:

答案 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/

链接到文档: http://ivaynberg.github.io/select2/#documentation

答案 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>