gpt4 book ai didi

jquery - 如何将 css 脚本和 jquery 脚本添加到 Laravel @extends ('layouts.app' ) @section ('content' )

转载 作者:行者123 更新时间:2023-11-28 15:55:25 24 4
gpt4 key购买 nike

我需要添加以下 css 和 jquery 脚本

<script src="{{('http://code.jquery.com/jquery-latest.js')}}"></script>
<script src="{{asset('js/jquery.bxSlider.js')}}"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#slider').bxSlider({
ticker: true,
tickerSpeed: 5000,
tickerHover: true
});
});
</script>

<link href="{{asset('css/style.css')}}" rel="stylesheet">

到 app.blade.php 文件

  <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="{{asset('favicon.ico')}}">

<title>Wealth </title>

<!-- Bootstrap core CSS -->
<link href="{{asset('css/bootstrap.min.css')}}" rel="stylesheet">

<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="{{asset('css/ie10-viewport-bug-workaround.css')}}" rel="stylesheet">

<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<script src="{{asset('js/ie-emulation-modes-warning.js')}}"></script>

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<link href="{{asset('css/carousel.css')}}" rel="stylesheet">

<body>
@yield('content')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery.min.js"><\/script>')</script>
<script src="{{asset('js/bootstrap.min.js')}}"></script>
<!-- Just to make our placeholder images work. Don't actually copy the next line! -->
<script src="{{asset('js/vendor/holder.min.js')}}"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="{{asset('js/ie10-viewport-bug-workaround.js')}}"></script>
</body>
</html>

并且需要将上面的 css 和 jquery 作为 @extends('layouts.app') 和 @section('content') 传递给另一个 Blade 文件怎么办???没有 @extends('layouts.app') 和 @section('content') 它可以工作但是有 @extends('layouts.app') 和 @section('content') 它不能工作...... .

最佳答案

Laravel 在 Blade 模板中有一个未记录的功能,称为“堆栈”。它们允许您定义一个部分并“推送”到它,而不必在 @section 标记中不断调用 @parent(并覆盖该部分的内容)。

堆栈看起来像这样:

<!-- resources/views/layouts/app.blade.php -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>@yield('title', config('app.name'))</title>
@stack('css')
</head>
<body>
<div id="app">
@yield('content')
</div>
@stack('scripts')
</body>
</html>

然后您可以像这样附加到这个堆栈:

<!-- resources/views/some-view.blade.php -->
@extends('layouts.app')

@push('css')
<link href="{{asset('css/style.css')}}" rel="stylesheet" />
@endpush

@push('scripts')
<script src="{{('http://code.jquery.com/jquery-latest.js')}}"></script>
<script src="{{asset('js/jquery.bxSlider.js')}}"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#slider').bxSlider({
ticker: true,
tickerSpeed: 5000,
tickerHover: true
});
});
</script>
@endpush

关于jquery - 如何将 css 脚本和 jquery 脚本添加到 Laravel @extends ('layouts.app' ) @section ('content' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41218442/

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