在 Drupal 中为 OnLoad 添加一个函数

2021-12-29 00:00:00 php javascript drupal

我的一个皮肤/主题的左侧栏中有一个 HTML/文本默认模块.我在那里有一些 Javascript 我试图将今天的日期设置为我的 javascript 日期下拉列表.我无法使用body.onLoad",因为 Drupal 以某种方式阻止了它?

I have a HTML/text default module in the left bar of one of my skins/themes. I have some Javascript in there I'm trying to set today date to my javascript date dropdowns. I am unable to use 'body.onLoad' because Drupal is blocking it somehow?

我找到了一个解决方案,说我可以在这里添加我的 javascript 函数:如果(isJsEnabled()){addLoadEvent(yourCustomJSFunction);}

I found a solution saying I can add my javascript function here: if (isJsEnabled()) { addLoadEvent(yourCustomJSFunction); }

如果我只使用默认的 HTML/文本模块,我该如何添加?

How can I add that if I'm just using a default HTML/text module?

谢谢!

推荐答案

Drupal 使用 jQuery JavaScript 库.您编写的用于 Drupal 的任何 JavaScript 最好也应该使用 jQuery.查看 api 上的 JavaScript 启动指南.drupal.org 了解一些基础知识,特别是 Drupal.behaviors 部分.

Drupal uses the jQuery JavaScript library. Any JavaScript you write to work with Drupal should ideally use jQuery as well. Check out the JavaScript Startup Guide on api.drupal.org for some basics, particularly the Drupal.behaviors section.

相关文章