doutizha7526
doutizha7526
2017-04-20 10:00

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?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • dongzhenyin2001 dongzhenyin2001 4年前

    Try like this

    <script src="{{ asset('/js/myjavascript.js') }}"></script>
    
    点赞 评论 复制链接分享
  • dongzhuo8210 dongzhuo8210 4年前

    <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

    点赞 评论 复制链接分享
  • donglao4370 donglao4370 4年前

    I think your code need to update like:

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

    Hope this work for you!

    点赞 评论 复制链接分享
  • duancha1065 duancha1065 4年前

    Try this:

    <script rel="text/javascript" src="{{ URL::asset('js/myjavascript.js') }}"></script>
    
    点赞 评论 复制链接分享

相关推荐