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="data:images/c_4.gif" /> 就可以了,前提是需要配置apache,把DocumentRoot 直接设置到public目录下,因为使用的都是相对路径.
转自:http://www.cnblogs.com/debmzhang/p/3500429.html
laravel加载javascript库的更多相关文章
- Ext JS 如何动态加载JavaScript创建窗体
JavaScript不需要编译即可运行,这让JavaScript构建的应用程序可以变得很灵活.我们可以根据需要动态从服务器加载JavaScript脚本来创建和控制UI来与用户交互.下面结合Ext JS ...
- ajax的使用:(ajaxReturn[ajax的返回方法]),(eval返回字符串);分页;第三方类(page.class.php)如何载入;自动加载函数库(functions);session如何防止跳过登录访问(构造函数说明)
一.ajax例子:ajaxReturn("ok","eval")->thinkphp中ajax的返回值的方法,返回参数为ok,返回类型为eval(字符串) ...
- 谈谈动态地加载Jquery库文件的方法
有时候,我们可能不会在网页中<script src="jquery.min.js" 来加载 Jquery 库,可能在用户点击某个按钮后,才去加载 Jquery 库. 好处不用 ...
- paip.ikanalyzer 重加载词库的方法.
paip.ikanalyzer 重加载词库的方法. 作者Attilax 艾龙, EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn ...
- 两种动态加载JavaScript文件的方法
两种动态加载JavaScript文件的方法 第一种便是利用ajax方式,第二种是,动静创建一个script标签,配置其src属性,经过把script标签拔出到页面head来加载js,感乐趣的网友可以看 ...
- NDK jni 加载静态库
加载静态库到android,静态库的提供方式有2种, a. 通过源文件来编译静态库 b. 加载已经编译好的静态库 首先我们来看,通过源文件来编译静态库,工程目录如下 第一步:我们来看我们的jni目录, ...
- Linux下c函数dlopen实现加载动态库so文件代码举例
dlopen()是一个强大的库函数.该函数将打开一个新库,并把它装入内存.该函数主要用来加载库中的符号,这些符号在编译的时候是不知道的.这种机制使得在系统中添加或者删除一个模块时,都不需要重新编译了. ...
- 网页特效-动态加载JavaScript
描述: 把一些逻辑独立的JavaScript脚本文件单独加载,是一种常见的JavaScript动态加载技术.可以减少不必要的JavaScript脚本文件的加载,以提高网页浏览速度 代码: <!D ...
- PostgreSql扩展Sql-动态加载共享库(C函数)
基于 psql (PostgreSQL) 10.4 pg_language表定义了函数实现所使用的语言.主要支持了C语言和SQL语句.一些可选的语言包括pl/pgsql.tcl和perl. ligan ...
随机推荐
- Posix 共享内存区
要点 与mmap配合使用 open与shm_open的区别,open打开磁盘上的普通文件,shm_open创建和打开的文件在/dev/shm文件夹下,该文件夹对应的是内存 gcc编译时加参数-lrt ...
- synchronized关键字使用剖析
synchronized关键字,代表这个方法加锁,相当于不管哪一个线程(例如线程A),运行到这个方法时,都要检查有没有其它线程B(或者C. D等)正在用这个方法,有的话要等正在使用synchroniz ...
- c++数组-矩阵的转置
#include <iostream> using namespace std; int main(){ ][]={{,,},{,,}}; ][]; ;j<;j++){ ;i< ...
- c/c++常用代码--清空目录
#pragma once #include <io.h>#include <stdio.h>#include <string>#include <direct ...
- Codeforces Round #333 DIV2
D: B. Lipshitz Sequence time limit per test 1 second memory limit per test 256 megabytes input stand ...
- How to use Android Activity's finish(), onDestory() and System.exit(0) methods
Activity.finish() Calling this method will let the system know that the programmer wants the current ...
- div均匀分布代码实例
多个div在同一行以相同间隔分布: 这样的布局效果使用非常的频繁,也就是让多个div在一行分布,并且div于div之间的间隙是一样的,多用在对于产品的展示之用,下面就介绍一下如何实现此中布局,代码实例 ...
- 【POJ】【3071】Football
概率DP kuangbin总结中的第10题 简单的画个比赛图,会发现是一颗完全二叉树,且同一层的子树之间各自独立,只有在合并得到更高一层结果时才结合. 所以我们可以按比赛轮数进行DP,f[i][j]表 ...
- 【BZOJ】【1103】【POI2007】大都市meg
dfs序 模板题,进点+1出点-1,刚好对于不在路径上的点一进一出刚好抵消,由于本题要动态修改(变成公路以后+1-1都变成0)所以在序列上套一个树状数组即可. TLE:1.递归dfs给爆了……写了个手 ...
- 【POJ】【2420】A Star not a Tree?
模拟退火 Orz HZWER 这题的题意是在二维平面内找一点,使得这点到给定的n个点的距离和最小……0.0 模拟退火算法请戳这里 //POJ 2420 #include<ctime> #i ...