doutizha7526
2017-04-20 10:00
浏览 98
已采纳

Laravel不会加载我的javascript文件

I have a javascript file in /public/js/ called myjavascript.js .

I want to include it in my site.

So I did this:

@extends('something')

    @section('scripts')
        <script src="/js/myjavascript.js"></script>
    @stop

@section('content')
...

This work in other project but not in this new one. What am I doing wrong?

图片转代码服务由CSDN问答提供 功能建议

我在 / public / js / 中有一个名为 myjavascript的javascript文件。 js

我想将它包含在我的网站中。

所以我这样做了:

  @extends('something')
 
 @section('scripts')
&lt; script src =“/ js / myjavascript.js”&gt;&lt; / script&gt; 
 @stop  
 
 @ section('content')
 ... 
   
 
 

此工作在其他项目中,但不在此新项目中。 我做错了什么?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • dongzhenyin2001 2017-04-20 10:05
    已采纳

    Try like this

    <script src="{{ asset('/js/myjavascript.js') }}"></script>
    
    已采纳该答案
    打赏 评论
  • duancha1065 2017-04-20 10:04

    Try this:

    <script rel="text/javascript" src="{{ URL::asset('js/myjavascript.js') }}"></script>
    
    打赏 评论
  • donglao4370 2017-04-20 10:10

    I think your code need to update like:

    {!! Html::script('js/myjavascript.js') !!}
    

    Hope this work for you!

    打赏 评论
  • dongzhuo8210 2017-04-20 12:52

    <script src="{{ asset('/js/myjavascript.js') }}"></script> is perfect.

    Check your APP_URL from .env file.

    if your APP_URL=www.example.com then your source will be www.example.com/js/myjavascript.js

    if your APP_URL=example.com/laravel then your source will be www.example.com/laravel/js/myjavascript.js
    Check 'https://github.com/laravel/framework/blob/5.4/src/Illuminate/Foundation/helpers.php' for more about asset helper function

    打赏 评论

相关推荐 更多相似问题