沃梦达 / 编程问答 / php问题 / 正文

如何在 Laravel 5 中包含外部 CSS 和 JS 文件

How to include External CSS and JS file in Laravel 5(如何在 Laravel 5 中包含外部 CSS 和 JS 文件)

本文介绍了如何在 Laravel 5 中包含外部 CSS 和 JS 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Laravel 5.0,从这个版本中删除了 Form 和 Html Helper,我不知道如何在我的头文件中包含外部 css 和 js 文件.目前我正在使用此代码.

I am Using Laravel 5.0 , the Form and Html Helper are removed from this version , i dont know how to include external css and js files in my header file. Currently i am using this code.

<link rel="stylesheet" href="/css/bootstrap.min.css"> <!---  css file  --->
<script type="text/javascript" src="/js/jquery.min.js"></script>

推荐答案

我认为正确的方法是这样的:

I think that the right way is this one:

<script type="text/javascript" src="{{ URL::asset('js/jquery.js') }}"></script>

这里我在 laravel 的 app/public 文件夹中有一个 js 目录.我有一个 jquery.js 文件.函数 URL::asset() 为您生成必要的 url.css 也一样:

Here I have a js directory in the laravel's app/public folder. There I have a jquery.js file. The function URL::asset() produces the necessary url for you. Same for the css:

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

希望这会有所帮助.

请记住旧方法:

{{ Form::script() }}

{{ Form::style() }}

已被弃用,不能在 Laravel 5 中使用!

are deprecated and will not work in Laravel 5!

这篇关于如何在 Laravel 5 中包含外部 CSS 和 JS 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在 Laravel 5 中包含外部 CSS 和 JS 文件

基础教程推荐