Using JQuery in Drupal 7

前端 未结 5 628
长情又很酷
长情又很酷 2021-01-30 17:18

I\'m writing my own Drupal 7 module, and like to use JQuery in it.

$(\'#field\').toggle();

But I\'m getting this error:

TypeErr         


        
5条回答
  •  猫巷女王i
    2021-01-30 17:57

    Chances are your script is not initialized this way, you'll have to use Drupal.behaviors.YOURTHEMENAME

    (function ($) {
    Drupal.behaviors.YOURTHEMENAME = {
    attach: function(context, settings) {
    
    /*Add your js code here*/
    alert('Code');
    
    }
    
    };
    })(jQuery);    
    

提交回复
热议问题