gpt4 book ai didi

laravel - 将 JS 脚本添加到 Laravel 页面

转载 作者:行者123 更新时间:2023-12-03 18:38:30 25 4
gpt4 key购买 nike

我正在尝试创建我的第一个 Laravel 站点,但我不知道如何将 JS 文件添加到我的一个页面中。

我只希望在此页面上使用 JS 文件,而不要在其他地方使用。

如何让我的页面加载 JS 文件?

我的目录结构是这样的:

apply
js
myjsfile.js
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 文件
<!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>

最佳答案

你的 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

你的 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>

关于laravel - 将 JS 脚本添加到 Laravel 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25951422/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com