Using JQuery in Drupal 7

前端 未结 5 616
长情又很酷
长情又很酷 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条回答
  •  执笔经年
    2021-01-30 17:37

    According to Firebug, your jQuery file is being loaded:

    alt text

    But the $ is being overwritten by something else:

    alt text


    What you should do is encapsulate the use of the $ variable with a function that invokes itself using the jQuery object as it's first actual argument:

    (function ($) {
    
     // in this function, you can use the $ which refers to the jQuery object
    
    }(jQuery));
    

提交回复
热议问题