2016-10-24 20 views
1

我想知道可能是什麼問題,因爲我已經嘗試了所有,這兩個建議早些時候給ST這種情況,他們似乎不是回答我的問題,請幫忙。我正在使用Select2,這些是我的文件。Uncaught TypeError:jQuery(...)。select2不是一個函數Larvael 5.3

@extends( 'layouts.app')

@section('content') 
<div class="container"> 
    <div class="row"> 
     <div class="col-md-8 col-md-offset-2"> 
      <div class="panel panel-default"> 
       <div class="panel-heading">Dashboard</div> 

       <div class="panel-body"> 
        <select name="primaryLanguage" id="primaryLanguage"> 
         <option value="AL">Alabama</option> 
         <option value="WY">Wyoming</option> 
        </select> 
       </div> 
      </div> 
     </div> 
    </div> 
</div> 
@endsection 
<script type="text/javascript" src="{{URL::asset('js/jquery-1.10.2.js')}}"></script> 
<script type="text/javascript" src="{{URL::asset('js/select2.full.min.js')}}"></script> 
<script type="text/javascript"> 
    jQuery(document).ready(function(){ 
     jQuery("primaryLanguage").select2(); 
    }); 
</script> 

錯誤我不斷收到:

home:7 Uncaught TypeError: jQuery(...).select2 is not a function(anonymous function) @ home:7fire @ jquery-1.10.2.js:3101self.fireWith @ jquery-1.10.2.js:3213jQuery.extend.ready @ jquery-1.10.2.js:3425completed @ jquery-1.10.2.js:3455 
jquery-1.9.0.js:1 '//@ sourceURL' and '//@ sourceMappingURL' are deprecated, please use '//# sourceURL=' and '//# sourceMappingURL=' instead. 
+0

你jquery沒有加載 – Araz

+0

也許404檢查控制檯 – Araz

+0

發表你如何包含jQuery和select2插件,因爲它似乎插件沒有被加載,而jQuery是。 – GillesC

回答

0

試圖修改此,

<script type="text/javascript"> 
    jQuery(document).ready(function(){ 
     jQuery("#primaryLanguage").select2(); 
    }); 
</script> 

在你的代碼,你指的是名稱爲primaryLanguage的標籤。但實際上它是一個id。因此,您錯過了#以指定具有特定'id'的tag

+0

當我編輯你的建議現在我現在得到的錯誤,因此:'jQuery.Deferred異常:jQuery(...) .select2不是函數TypeError:jQuery(...)。select2不是HTMLDocument的函數 。 (http:// localhost:8000/js/jquery-3.1.1.min.js:2:29948) at k(http:// localhost:8000/home:7:35) //localhost:8000/js/jquery-3.1.1.min.js:2:30262)undefined jquery-3.1.1.min.js:2 Uncaught TypeError:jQuery(...)。select2不是函數''' – kehinde

+0

非常感謝您的支持。 – kehinde

+0

正如@Araz在評論中提到的,你的Js文件是否正確加載? – Samir

1

我只是面對自己的問題,我解決了這個問題是這樣的: 在主佈局文件,把這些

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
<script src="/js/select2.min.js"></script> 

(在我的情況app.blade.php) 然後根據這些腳本把 @yield('scripts') 然後在你要撥打的插件刀片文件時,

@section('content') 
... 
@endsection 
@section('scripts') 
<!-- Here you call the select2 js plugin --> 
@endsection 

經過PS:你必須把css文件& JS文件下公共文件夾(公共/ CSS &公共/ JS) 這裏我使用Laravel集體的形式 我希望我幫助

0

在您的代碼primaryLanguage你作爲id,所以現在改變了一小段代碼:

<script type="text/javascript"> 
    jQuery(document).ready(function(){ 
    jQuery("#primaryLanguage").select2(); 
    }); 
</script> 
相關問題