javascript - $ 不是 Drupal 上的函数错误

标签 javascript jquery drupal drupal-7 counter

我的代码在本地环境中运行良好,但在网站上运行不正常。我不明白我在这里错过了什么。

代码:

jQuery(document).ready(function(){
  'use strict';
  //============================== COUNTER-UP =========================
  $('.counter').counterUp({
    delay: 10,
    time: 2000
  });
});

错误信息:

Uncaught TypeError: $ is not a function
    at HTMLDocument.<anonymous> (custom.js?p4xosk:4)
    at fire (jquery.js?v=1.10.2:3048)
    at Object.fireWith [as resolveWith] (jquery.js?v=1.10.2:3160)
    at Function.ready (jquery.js?v=1.10.2:433)
    at HTMLDocument.completed (jquery.js?v=1.10.2:104)

最佳答案

你必须定义 $ :

(function($){
 $(document).ready(function(){
  'use strict';
  //============================== COUNTER-UP =========================
  $('.counter').counterUp({
    delay: 10,
    time: 2000
  });
 });
})(jQuery);

关于javascript - $ 不是 Drupal 上的函数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49060058/

相关文章:

javascript - 触发点击 n 在 javascript 中创建的元素并下载 csv 文件

Drupal 7 hook_theme() 不加载模板文件

javascript - 部分显示和隐藏 DIV

javascript - JavaScript 是否有 "Short-circuit"评估?

javascript - 将 Bootstrap 类添加到按钮

jquery - 添加命名空间后 Bootstrap 模式不起作用

mysql - 重新启动MySQL使应用程序更快

Drupal, View : trimming text doesn't work because tags are not closed properly

javascript - 当数据库img标签中没有条目时仍然显示空框

javascript - 许多对象的模态 Rails Form_for