Using jQuery with CSS in Drupal 7 “Zen” theme

て烟熏妆下的殇ゞ 提交于 2019-12-11 14:08:32

问题


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.


回答1:


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');
  });
};



回答2:


you should determine $ like

(function($) {
  Drupal.behaviors.mybehavior = {
    attach: function(context, settings){
       //you code goes here
       //$ will work inside this function
    }
  };
})(jQuery);


来源:https://stackoverflow.com/questions/14503814/using-jquery-with-css-in-drupal-7-zen-theme

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!