我正在开发一个 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/