添加Javascript文件

0.6.2

从Seagull 0.6.2版本开始,你可以在manager内调用$output→addJavascriptFile($file)来添加任意的javascript文件。

This method takes a single param that can be either a single string or an array of files to load, relative to the SGL_WEB_ROOT, i.e. the www folder in your Seagull install: 这个方法只带一个参数,这个参数可以是一个字符串也可以是一个要载入文件的数组,这些文件路径是相对于SGL_WEB_ROOT的,比如你安装的Seagull的www目录:

  $output->addJavascriptFile('js/global.js');

  $output->addJavascriptFile(array(
      'relative/path/to/js/file.js',
      'http://www.example.com/js/file.js
  ));

都是可以的。你可以注意到,你使用绝对路径也可以包含一个远程的javascript文件。 Also you now have the possibility to require a file that will be loaded in every page of your site. 当然,你现在也可以添加在整个站点每个页面都需要加载的javascript文件。

在全局配置文件中添加你要全局加载的javascript文件:

$conf['site']['globalJavascriptFiles'] = 'js/file';

当然你可提供多个文件,文件之间用分号”;”隔开

$conf['site']['globalJavascriptFiles'] = 'js/file1.js;js/file2.js';

使用绝对路径包含远程文件

$conf['site']['globalJavascriptFiles'] = 'http://www.google-analytics.com/urchin.js';

在0.6.2 版本之前

要在manager中加载特定的javascript文件,只需要创建一个数组,这个数组可以包含一个或一个以上的文件名,然后将这个数组赋值给output对象的javascriptSrc属性。注意数组中每个元素即文件的路径要使用从webroot开始的相对路径。

  $output->javascriptSrc = array('js/PageView.js','js/packaging.js');

这行代码将添加js/PageView.js和js/packaging.js 两个文件到你的html文件的 <head>标签内。

请参考

 
howto/javascript/includefiles.txt · 最后更改: 2010/05/30 00:21 (外部编辑)
 
Except where otherwise noted, content on this wiki is licensed under the following license:GNU Free Documentation License 1.2