简体   繁体   English

如何从Drupal模块文件中的.js文件调用javascript函数

[英]How to call a javascript function from .js file in a Drupal module file

I'm trying to modify an existing module to insert collapsible div. 我正在尝试修改现有模块以插入可折叠div。 my javascript functions are in the file 'my_module.js' and look like that : 我的javascript函数位于文件“ my_module.js”中,如下所示:

my_module.js

function myFunction1(param){
...
}

function myFunction2(paramA, paramB){
...
}

I added my_module.js in module file using drupal_add_js and then I don't know what to do next! 我使用drupal_add_js在模块文件中添加了my_module.js,然后我不知道下一步该怎么做!

<?php

    drupal_add_js(drupal_get_path('module', 'my_module') . '/my_module.js');
    // -----> I want to call myFunction2 here !!
?>

The website has Drupal core 6.24. 该网站具有Drupal核心6.24。

thx 谢谢

Just continue with my_module.js as normal javascript file. 只需继续使用my_module.js作为普通的javascript文件即可。 You can try to insert div by using JQuery. 您可以尝试使用JQuery插入div。

$("#foo").append("<div id='my_collapsible'>hello world</div>")

And by JQuery attach to #my_collapsible some actions you want (make it collapsible). 并通过JQuery附加到#my_collapsible您想要的一些动作(使其可折叠)。

That method should actually work. 该方法实际上应该有效。

Have you: 你有:

  • Checked the file paths are correct 检查文件路径是否正确
  • Checked in firebug/webkit inspector that the JS file is being loaded? 在firebug / webkit检查器中签入了JS文件吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM