简体   繁体   English

jQuery在Laravel中不起作用

[英]jQuery does not work in Laravel

I tried to use a web library, and now I use it locally (also NPM installed it), but the function on button click doesn't give me any response. 我尝试使用网络库,现在我在本地使用它(也已NPM安装了它),但是单击按钮时的功能没有任何响应。 The console log is also completely empty. 控制台日志也完全为空。 No more ideas on how to make it work. 没有更多有关如何使其工作的想法。

Here is my code: 这是我的代码:

<!doctype html>
    <head>
        <link rel="stylesheet" href="/css/app.css">
        <script src="{{asset('js/jquery.min.js')}}"></script>
    </head>

    <body>
        @include('inc.navbar')   
        <div class = 'container'>
            <div class = 'row'>
                <div class = 'col-md-8 col-lg-8' >
                    @include('inc.messages')
                    @yeld('content')
                    <button class = 'btn' id = 'test1'>SES</button>
                </div>
            </div>
        </div>
    </body>

    <footer id='footer' class = 'text-center'>
        <p>Copyright 2018 &copy; FitnessBook </p>
    </footer>

    @section('script')

    <script>
      $( "#test1" ).click(function(){
           alert( "Handler for .click() called.");
      });
    </script>

    @endsection

</html>

You have to add your footer tag and script inside body of HTML document. 您必须在HTML文档的body中添加footer标记和script

and replace your script tag with below code : 并用以下代码替换您的脚本标签:

<script>
$(document).on('click','#test1',function(){
  alert("Hello !!!");
});
<script>

I found the solution. 我找到了解决方案。 Removing @section('script') and adding the script src of cdn solved the problem. 删除@section('script')并添加cdn的脚本src解决了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM