TypeError:jQuery(…).ready(…)不是函数
好的,我知道之前已经问过,但没有一个答案似乎适用于我的情况。 我正在尝试运行一小段jQuery(我刚刚开始使用它)。
jQuery(document).ready(function(){ jQuery('.comtrig').on('click',function(){ $(this).next().animate({'display':'inline'},1000); }); })();
我得到错误TypeError: jQuery(...).ready(...) is not a function
FF或Uncaught TypeError: object is not a function
Chrome中Uncaught TypeError: object is not a function
。
- 解决方案1是用
jQuery
替换$
,但我显然已经如上所示那样做了 - 我也不在Wordpress中
- 我只使用jQuery和上面的迷你脚本,没有其他JS
- jQuery本身似乎加载得很好
我在这里想念的是什么?
尝试删除this ();
在doc准备结束时:
jQuery(document).ready(function(){ jQuery('.comtrig').on('click',function(){ $(this).next().animate({'display':'inline'},1000); }); }); //<----remove the (); from here
();
通常用于具有立即调用的函数表达式(IIFE) ,其具有如下的某种语法:
(function(){ // your stuff here })(); //<----this invokes the function immediately.
你的错误:
在firefox = TypeError: jQuery(...).ready(...) is not a function
in chrome = Uncaught TypeError: object is not a function
因为:
您的文档就绪处理程序不是自执行匿名函数 。
代码中有两个问题。
1 – 代码末尾的括号。
2 – $(this)应该是jQuery(this)或$ inside函数。
jQuery(document).ready(function($){ $('.comtrig').on('click',function(){ $(this).next().animate({'display':'inline'},1000); }); });
删除末尾的额外括号()
。 保持代码如下。
jQuery(document).ready(function(){ jQuery('.comtrig').on('click',function(){ $(this).next().animate({'display':'inline'},1000); }); }); // <== remove () from here
以这种方式传递jquery对象对我有用。
$(document).ready(function () { console.log("jquery"); }(jQuery));
这些错误:
TypeError: jQuery(...).ready(...) is not a function or Uncaught TypeError: object is not a function
如果你在代码之后实现Jquery库也会发生,它应该在之前, ORDER MATTER在这里 。