• laravel加载javascript库


    一篇文章:

    Generating a Link to a Javascript File

    Problem

    You want your Blade template to load an external javascript file.

     

    Instead of using <script ...> directly, you want to do this with the HTML facade.

     

    Solution

    Use the HTML::script() method.

     

    Just pass the path to the javascript file.

    {{ HTML::script('js/functions.js') }}

    This produces the following HTML code.

    <script src="http://your.url/js/functions.js"></script>

    If the file path you pass isn't a complete URL, Laravel will use your application's URL to build a complete URL.

    You can pass additional attributes in an array as the second argument.

    {{ HTML::script('js/functions.js', array('async' => 'async')) }}

    The attributes will be added to the script tag as the result below illustrates.

    <script async="async" src="http://your.url/js/functions.js"></script>
     

    Discussion

    The type attribute of <script> tags is optional with HTML5.

    But if your web page is still HTML 4.01, you should add the "type" => "text/javascript" to the attributes you pass this method.

    转自:http://laravel-recipes.com/recipes/183

    写在前面的话:

    1.前提是需要使用blade模板引擎

    2.css js image 文件夹建在laravel 的 public 目录下面

    3.生成的路径默认都是相对路径

    A: 加载css文件 (用下面的格式把正常的link替换掉)

    {{ HTML::style('css/custom.css') }}

    在页面里生成的样子如下

    <link media="all" type="text/css" rel="stylesheet" href="http://local.lv.com/css/custom.css">

    B: 加载js文件 (用下面的格式把正常的script替换掉)

    {{ HTML::script('js/custom.js') }}

    在页面里生成的样子如下

    <script src="http://local.lv.com/js/custom.js"></script>

    C: 页面里加图片(同样去掉img标签)

    {{HTML::image('images/hot_1.gif')}}

    生成的样子

    <img src="http://local.lv.com/images/c_4.gif">

    如果想自定义img的话(加入alt或是title之类的属性),那就什么都不用改,直接使用<img src="images/c_4.gif" /> 就可以了,前提是需要配置apache,把DocumentRoot 直接设置到public目录下,因为使用的都是相对路径.

    转自:http://www.cnblogs.com/debmzhang/p/3500429.html

  • 相关阅读:
    插入排序(JS代码)
    选择排序(JS代码)
    快速排序(JS代码)
    冒泡排序(js代码)
    《CSS揭秘》--推荐指数⭐⭐⭐⭐⭐
    CSS中position的定位
    逆转录转座子初窥
    django开发傻瓜教程-1-安装和HelloWorld
    爬虫教程-1
    算法_NP_证明
  • 原文地址:https://www.cnblogs.com/youxin/p/3967241.html
Copyright © 2020-2023  润新知