對於Drupal,你應該添加你的腳本drupal_add_js()
。您可以添加文件或內聯js,並設置多個選項,例如它應該出現在每個頁面上,還是應該添加到頁腳或頁眉以及是否需要jQuery。
你可以創建一個像這裏面一個js文件:
jQuery(document).ready(function($) {
var mySound = document.createElement('audio');
mySound.setAttribute('src', '/path/to/my/sound.mp3');
//play the sound when the visitor moves the mouse over
//an element with the class 'picture'.
$('.picture').mouseover(function() {
mySound.play();
});
});
然後在你的主題或模塊,你可以使用hook_page_alter
添加您的JS:
drupal_add_js(
'/path/to/js/script.js',
array(
'type' => 'file',
'scope' => 'footer',
'group' => JS_THEME, //or JS_DEFAULT if module
'every_page' => false,
'requires_jquery' => true,
)
);
你可以換行在某種if語句中只將它加載到你需要的頁面上。
希望有幫助!
嗨!很多tks。這真的很有用!:-) – drupal