0

我有一个 ctools 内容类型插件,其中包含一个模板文件,其中包含以下 html:

<a id="blah">Click me</a>
<p class="green-button"><a href="#">Read the blog</a></p>
<ul class="buying-dropdown">

      <li class="first amazon"><a href="#">paperback</a></li>
      <li class="signed"><a href="#">Signed edition</a></li>
      <li class="kindle"><a href="#">kindle edition</a></li>
      <li class="hardback"><a href="#">hardback edition</a></li>
      <li class="last postcard"><a href="#">postcard edition</a></li>
</ul>

我试图简单地在 p 按钮的鼠标悬停时显示 ul,在悬停期间保持状态并选择不同的子 li,然后在鼠标悬停时消失。

正在调用 javascript 文件,就好像我在控制台中查看然后控制台正在写入“调用”。但是,我简单的“点击我”按钮测试不起作用。我还尝试使用菜单实现主要目标(按照本教程http://www.queness.com/preview/1047/easy-to-style-jquery-drop-down-menu-tutorial),但似乎我的脚本没有被调用。任何帮助表示赞赏。

(function ($, Drupal, window, document, undefined) {
    console.log('called');
    $('#blah').click(function() { console.log('clickity click')});
    //when someone mouseovers the buy book button
    //the menu will show (it is hidden by default  
    //the menu will stay open whilst hovering over   
    //on mouseout the menu disappears
})(jQuery, Drupal, this, this.document);
4

1 回答 1

1

这就是解决方案。最初在 Drupal 7 中使用 JQuery上回答

  (function ($) {
    Drupal.behaviors.YOURTHEMENAME = {
    attach: function(context, settings) {

     console.log('called');
        $('#blah').click(function() { console.log('clickity click')});
        //when someone mouseovers the buy book button
        //the menu will show (it is hidden by default  
        //the menu will stay open whilst hovering over   
        //on mouseout the menu disappears
    }

    };
    })(jQuery);    
于 2013-03-24T12:46:51.830 回答