2016-10-24 22 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> 
相关问题