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

标签 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

警报未显示。

最佳答案

确保在您的 layouts/app.blade.php 中有 Blade @yield('scripts') 标记来选取 @section ('script') Blade 标签:

示例:

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

            ...

            @yield('content')

        </div>

        @yield('scripts')

    </body>
</html>

关于javascript - 我的 Javascript 代码没有在 laravel 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47252198/

相关文章:

javascript - 如何使用jquery获取div元素的html内容

javascript - 使用 Javascript 解析 JSON 对象是行不通的

javascript - Angular Directive(指令) : scope vs bindToController

javascript - 在 React 中检查密码验证

php - 长 PHP 脚本和回显/打印

javascript - 选中该字段的复选框时设置 Attr Required

php - 我怎样才能在PHP中制作一个动态下拉框?

一个文件夹中的 PHP 文件正在执行,但在其他几个文件夹中没有执行

java - 密码错误解密java

javascript - jquery-获取不同的页面元素