[Drupal] How to add the js file and js code block in Drupal
生活随笔
收集整理的這篇文章主要介紹了
[Drupal] How to add the js file and js code block in Drupal
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Drupal 6:
?代碼
??//?This?will?add?a?JS?file?to?your?head?(specifically?the?$scripts?variable?in?page.tpl.php)??drupal_add_js(drupal_get_path('module',?'my_module')?.?'/my_module.js');
??//?This?add?inline?JS?to?the?head?of?the?document
??drupal_add_js('alert("Hello!")',?'inline');
??//?This?will?add?variables?in?the?Drupal.settings?object
??drupal_add_js(array('my_module'?=>?array('my_setting'?=>?'this_value')),?'setting');
??
??//add?an?external?JS?file?to?your?site.
??//You?can?not?add?<script?XXXX??/>,?but?you?have?to?add?as?<script?XXX></script>,
??//because?the?first?one?will?cause?some?problem?(webkit-base?browser)
??drupal_set_html_head('<script?type="text/javascript"?src="http://maps.google.com/maps/api/js?sensor=false"></script>');
?
?
?Drupal 7:
代碼??drupal_add_js('misc/collapse.js');??drupal_add_js('misc/collapse.js',?'file');
??drupal_add_js('jQuery(document).ready(function?()?{?alert("Hello!");?});',?'inline');
??drupal_add_js('jQuery(document).ready(function?()?{?alert("Hello!");?});',
????array('type'?=>?'inline',?'scope'?=>?'footer',?'weight'?=>?5)
??);
??drupal_add_js('http://example.com/example.js',?'external');
??drupal_add_js(array('myModule'?=>?array('key'?=>?'value')),?'setting');
?
?
Details:?http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_add_js?
轉(zhuǎn)載于:https://www.cnblogs.com/davidhhuan/archive/2010/12/14/1905672.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的[Drupal] How to add the js file and js code block in Drupal的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Win32汇编--加载菜单资源
- 下一篇: OEA 框架中集成的 RDLC 报表介绍