Add a function to OnLoad in Drupal

2019-05-23 00:58发布

问题:

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?

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

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

Thanks!

回答1:

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.