jquery.min.js:2未捕获的TypeError:$(...)。select2不是函数

时间:2018-10-06 17:02:23

标签: javascript

用于选择的表单,此表单看起来像选择,然后选择代码

<div class="form-group">
                        <label>Multiple</label>
                      <select class="form-control select2 select2-hidden-accessible" multiple="" data-placeholder="Select a State" style="width: 100%;" tabindex="-1" aria-hidden="true" name="select2">
                          <option>Alabama</option>
                          <option>Alaska</option>
                          <option>California</option>
                          <option>Delaware</option>
                          <option>Tennessee</option>
                          <option>Texas</option>
                          <option>Washington</option>
                        </select>
                        </div>   

这是链接代码错误,这里是JavaScript函数上的错误

         @section('footerSection')
              <script  language="JavaScript" type="text/javascript" src="{{ asset('/admin/bower_components/select2/dist/js/select2.full.min.js')}}"></script>
            <script language="JavaScript" type="text/javascript" src="{{ asset('/admin/bower_components/jquery/dist/jquery.min.js')}}"></script>

            <script type="text/javascript"> 
             $( document ).ready(function() {

               $(".select2").select2();

              });
            </script>
             @endsection

1 个答案:

答案 0 :(得分:0)

您需要切换src顺序。 select2可能试图在定义jquery之前使用它。

<script language="JavaScript" type="text/javascript" src="{{ asset('/admin/bower_components/jquery/dist/jquery.min.js')}}"></script>
<script  language="JavaScript" type="text/javascript" src="{{ asset('/admin/bower_components/select2/dist/js/select2.full.min.js')}}"></script>