将 JS 脚本添加到 Laravel 页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25951422/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding a JS script to a Laravel page
提问by imperium2335
I am trying to create my first Laravel site, but I can't figure out how to add a JS file to one of my pages.
我正在尝试创建我的第一个 Laravel 站点,但我不知道如何将 JS 文件添加到我的一个页面中。
I only want the JS file to be used on this page and no where else.
我只希望在此页面上使用 JS 文件,而不要在其他地方使用。
How do I get my page to load the JS file?
如何让我的页面加载 JS 文件?
My directory structure is like so:
我的目录结构是这样的:
apply
js
myjsfile.js
apply.blade.php
In my apply.blade.php
在我的 apply.blade.php
@extends('layouts.master')
@section('content')
<div class="row">
<div id="applicationForm" class="col-md-9 col-xs-12">
...
</div>
</div>
layouts.master file
layouts.master 文件
<!DOCTYPE html>
<html>
<head>
@include('includes.head')
</head>
<body>
<div class="container">
<div id="header">
@include('includes.header')
</div>
@yield('content')
<div id="footer">
@include('includes.footer')
</div>
</div>
</body>
</html>
回答by worldask
your apply.blade.php
您的 apply.blade.php
@extends('layouts.master')
@section('content')
<div class="row">
<div id="applicationForm" class="col-md-9 col-xs-12">
...
</div>
</div>
@stop
@section('myjsfile')
<script src="js/myjsfile.js"><script>
@stop
your layouts.master
您的 layouts.master
<!DOCTYPE html>
<html>
<head>
@include('includes.head')
</head>
<body>
<div class="container">
<div id="header">
@include('includes.header')
</div>
@yield('content')
<div id="footer">
@include('includes.footer')
</div>
</div>
@yield('myjsfile')
</body>
</html>