使用drupal中自定义javascript文件中的一个函数

using a function in custom javascript file in drupal

本文关键字:一个 函数 drupal 自定义 javascript 文件 使用      更新时间:2023-09-26

我制作了一个创建块的模块,并使用#attached添加了我的自定义.js文件来块内容,没有Drupal。行为和函数($)我的代码在另一个页面(Drupal之外)中就像时钟一样工作,但在Drupal中,我不知道如何在.js文件中添加函数这是我的代码:

(function($){
    Drupal.behaviors.mymodule = {
    attach:function(context, settings) {
                function show_more(count){
                var counter = count;
                var id = document.getElementById("id").value;
                var xmlhttp;
                if (window.XMLHttpRequest)
                {
                    xmlhttp=new XMLHttpRequest;
                }
                xmlhttp.onreadystatechange = function() {
                if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    document.getElementById("div_id").innerHTML =xmlhttp.responseText;
                }
                }
                xmlhttp.open("POST","some_page.php",true);
                xmlhttp.setRequestHeader("Content-type","application/x-www-form-        urlencoded");
               xmlhttp.send("counter="+encodeURIComponent(counter)+"&id="+encodeURIComponent(id    ));
            $("#div_id").fadeToggle(2000);
               }
        }
    }
       })(JQuery);

我是drupal和Jquery的新手,请帮帮我请告诉我如何在我的内容中调用showmore函数提前感谢

您可以通过主题或drupal_add_JS($data=NULL,$options=NULL)函数包含JS文件。只需将函数写入文件并简单使用即可。此文件及其功能将在您的整个网站页面上提供。