當(dāng)前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Drupal 引入JS文件的几种方式
生活随笔
收集整理的這篇文章主要介紹了
Drupal 引入JS文件的几种方式
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1、在 theme.info 中,通過增加 scripts 節(jié)點(diǎn)的方式增加JS文件,如
scripts[] = foo.js
2、在 template.php 中,DP提供了以下文件來加載JS文件
Drupal 6 中,使用以下方式:
function example_preprocess_page(&$variables) {drupal_add_js(drupal_get_path('theme', 'example'). '/foo.js', 'theme');// We need to rebuild the scripts variable with the new script included.$variables['scripts'] = drupal_get_js();} Drupal 7 中,使用以下方式: function example_preprocess_html(&$variables) {$options = array('group' => JS_THEME,);drupal_add_js(drupal_get_path('theme', 'example'). '/foo.js', $options);}3、還可以通過以下方式載入庫文件
drupal_add_library('system', 'ui.autocomplete');
通過這個(gè)方法載入的文件有: jquery.ui.autocomplete.js, jquery.ui.autocomplete.css, and the dependencies of jquery.ui.position.js, jquery.ui.widget.js, jquery.ui.core.js, jquery.ui.core.css, and jquery.ui.theme.css.
原文鏈接:https://drupal.org/node/171213
總結(jié)
以上是生活随笔為你收集整理的Drupal 引入JS文件的几种方式的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Drupal 通过API动态的添加样式文
- 下一篇: Drupal 自定义主题实体 Themi