【问题标题】:using drupal and bootstrap subtheme - jquery not working使用 drupal 和 bootstrap 子主题 - jquery 不工作
【发布时间】:2013-10-22 15:18:06
【问题描述】:

当我输入诸如 alert("hello"); 之类的代码时,我有引导主题(使用子主题)并包含了我自己的 scripts.js 文件(来自我的 .info);然后它工作正常。但是当我尝试 $('#edit-profile-teacher').hide(); 时没有任何反应

控制台中没有错误,我不知道为什么这么基本的东西不起作用。

我正在使用 jquery 更新模块并将其设置为 1.7

干杯, 加里。

【问题讨论】:

  • 检查你是否把jquery放了两次...一定是冲突

标签: jquery twitter-bootstrap drupal


【解决方案1】:

您应该通过扩展 Drupal 行为来提供所有 JS 代码;像这样:

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

      // Do anything you want here.
      $('#some-selector').hide();

    }
  };
})(jQuery);

虽然其他方法也可以使用(例如,仅添加文档加载),但这是在 Drupal 主题中添加 JS 的正确方法。

【讨论】:

    【解决方案2】:

    我必须在其中包装 jquery 才能在 drupal 中工作。

    (function($){
    $(document).ready(function(){
        //your stuff here
        alert('what up?!');
        $('#edit-profile-teacher').hide();
    });
    }(jQuery));
    

    【讨论】:

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