【问题标题】:How to write some jquery script in drupal 7?如何在 drupal 7 中编写一些 jquery 脚本?
【发布时间】:2015-06-30 04:49:08
【问题描述】:

如何在drupal-7 中编写jquery 脚本?我的工作网站上需要一些 jquery 幻灯片切换动画。这是我迄今为止尝试过的:

$(document).ready(function () {
  $('div.toggle_area').find('div.toggle_content').hide().end().find('div.toggle_label').click(function() {
    $(this).next().slideToggle(); 
  });
});

【问题讨论】:

  • 我是 drupal-7 的初学者,我需要我的工作站点一些 jquery slidetoggle 动画..我尝试在 drupal 7 中使用 html 编辑器编写代码,但有一次编写代码然后保存并退出,再次在 html 编辑器中看不到代码。在drupal 7中制作代码的地方????????*

标签: jquery drupal-7


【解决方案1】:

为此使用 drupal_add_js 函数。

drupal_add_js("jQuery(document).ready(function () {   
                 jQuery('div.toggle_area').find('div.toggle_content').hide().end().find('div.toggle_label').click(function() {
                   jQuery(this).next().slideToggle(); 
                 });
               });", 'inline');  

手册:

https://api.drupal.org/api/drupal/includes!common.inc/function/drupal_add_js/7

【讨论】:

    【解决方案2】:

    (函数($){

    Drupal.behaviors.YOURTHEMENAME = {

    附加:功能(上下文,设置){

    /在此处添加您的 js 代码/

    //使用 comm 作为类值,因为您想对多个元素进行分组 $('.ticks').click(function() {

    //if you want to hide previously opened comment when a new one is clicked
    $('.comments').slideToggle("slow");
    

    });

    $('.ticks1').click(function() {
    
    
    $('.comments1').slideToggle("slow");
    

    });

    }

    }; })(jQuery);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多