Using jQuery with CSS in Drupal 7 “Zen” theme

2019-09-13 23:46发布

I'm editing the "Zen" theme in Drupal 7. And that's the problem:

 (function ($, Drupal, window, document, undefined) {        
         alert("xuy");
         $("#navigation ul.links li").hover(function() {
         alert("xuy");
    });

The first alert is working well, but there is no alert on hover. I've got this class in CSS. Even

 $("a").hover(function() { 
          alert("xuy"); 
    });

Didn't work.

2条回答
劳资没心,怎么记你
2楼-- · 2019-09-14 00:26

Your code looks a little funky to me. Shouldn't you be using drupal behaviors in drupal 7? (yes you should).

Drupal.behaviors.mybehavior = function(context, settings){
  $('#navigation ul.links li').hover(function() {
    alert('xuy');
  });
};
查看更多
叛逆
3楼-- · 2019-09-14 00:27

you should determine $ like

(function($) {
  Drupal.behaviors.mybehavior = {
    attach: function(context, settings){
       //you code goes here
       //$ will work inside this function
    }
  };
})(jQuery);
查看更多
登录 后发表回答