通过使用drupal add js调用函数



我正在调试一个drupal模块,第二行drupal_add_js调用uc_discount .js中的js函数

drupal_add_js(drupal_get_path('module', 'uc_discounts') . '/uc_discounts.js');
drupal_add_js('(function($){jQuery(document).ready(function () { uc_discountsOnLoad(e); })})(jQuery);', array('type' => 'inline', 'group' => JS_DEFAULT, 'scope' => 'footer'));

firebug中有一个错误信息,ReferenceError: uc_discountsOnLoad没有定义,有人能找出问题吗?

** update **

我知道问题所在!

uc_discountsOnLoad如果定义外部(函数($){})(jQuery);可以调用~但是不能使用jquery符号,这是冲突!但是在这种情况下,我怎么调用这个函数呢?

function uc_discountsOnLoad(e) {
  context = $('body');
  uc_discountsProcessCodes(context, e);
  //Add click event listener to discounts pane button once
  $("input[id*=uc-discounts-button]:not(.uc_discountsOnLoad-processed)", 
    context).addClass("uc_discountsOnLoad-processed").click(function(e) {
      uc_discountsProcessCodes(context, e);
      //Return false to prevent default actions and propogation
      return false;
    });
}

如果在(function ($) {})(jQuery);之外定义uc_discountsOnLoad(e), $('body')将得到一个错误!

无法找到uc_discountsOnLoad(e)函数。

  • 检查uc_discounts.js是否存在

  • uc_discounts.js在函数调用后加载?

最新更新