我的Javascript代码没有在laravel中运行

时间:2017-11-12 18:11:14

标签: javascript php jquery laravel-5

我正在开发一个Laravel项目,我的Javascript代码不是措辞。我已应用警报但未显示。当用户点击该按钮时,它将显示警报但未显示。

 @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

            <button id="read-data" class="btn btn-info pull-right btn-xs">Load Data By Ajax</button>
            </div>

            <div class="panel-body">
            <table class="table table-bordered table-striped table-condensed">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>First Name</th>
                        <th>Last Name</th>
                        <th>Full Name</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>

                    </tr>
                </tbody>
            </table>
            </div>
        </div>
    </div>
   </div>
   </div>
       @endsection

       @section('script')

     <script type="text/javascript" charset="utf-8">
      $('#read-data').on('click', function(){

      alert('sdsdsd');

      });
       </script>


    @endsection

警报未显示。

1 个答案:

答案 0 :(得分:2)

确保在layouts/app.blade.php您拥有刀片@yield('scripts')标记,以获取@section('script')刀片代码:

示例:

<!DOCTYPE html>
<html lang="{{ config('app.locale') }}">
    <head>
        ...
    </head>
    <body>
        <div id="app">

            ...

            @yield('content')

        </div>

        @yield('scripts')

    </body>
</html>