LeB*_*eau 3 jquery drupal drupal-7
我有一个模块,在其中我添加了js
if($_GET['q'] == 'workpage') {
drupal_add_js(drupal_get_path('module', 'sb_carousel').'/js/slide.js');
}
Run Code Online (Sandbox Code Playgroud)
问题是它将它添加到.info文件中定义的jqueru之上.我看到有一个'权重'属性如何让我的js在js文件的底部?
您可以通过将$options
数组传递给drupal_add_js()来设置权重:
$file = drupal_get_path('module', 'sb_carousel').'/js/slide.js';
$options = array(
'weight' => 1000, // High number to push this file to the bottom of the list
'scope' => 'footer' // This will output the JS file in the footer scope, so at the end of the document
);
drupal_add_js($file, $options);
Run Code Online (Sandbox Code Playgroud)
使用weight
和scope
你应该能够确保你的JS文件是HTML中输出的最后一个.
UPDATE
只是一个想法,你提到你的jQuery文件是从一个.info
文件加载的...没有必要这样做,默认情况下已经在Drupal中添加了jQuery.您可以使用jQuery Update模块升级到jQuery 1.5,但目前没有(官方)支持任何更高版本.
如果您正在加载第二个jQuery文件,它可能是导致问题的原因,除非您jQuery.noConflict()
正确使用,即使这样您仍可能遇到问题.