select2插件在laravel 5中不起作用

时间:2016-08-06 20:06:35

标签: laravel-5 select2 ui-select2

我想使用多个选择框作为标签和头部我放:

 <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet" />

我的观点:

 <div>

{!! Form::label('tags','Select Tags:') !!}
 <select class="form-control select2-multi" multiple="multiple" name="tags">

@foreach($ tags as $ tag)

    <option value='{{ $tag->id }}'>{{ $tag->name }}</option>

 @endforeach

 </select>

 <script type="text/javascript">
$(.select2-multi).select2();

在浏览器中我得到了这个: enter image description here

1 个答案:

答案 0 :(得分:1)

$(document).ready(function() {
  $(".js-example-basic-single").select2();
  $(".js-example-basic-multiple").select2();
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
<br>
<strong>Single Select</strong>
<select class="js-example-basic-single form-control">
    <option value="AL">Alabama</option>
    <option value="WY">Wyoming</option>
</select>
<br><br>
<strong>Multi Select</strong>
<select class="js-example-basic-multiple form-control" multiple>
    <option value="AL">Alabama</option>
    <option value="WY">Wyoming</option>
</select>

它的工作非常好。 确保您已包含所有必需的cssjs plugins

注意:

  1. 为单选js-example-basic-single选项
  2. 添加此类
  3. js-example-basic-multiple用于多选选项