TypeError:jQuery(...)。ready(...)不是函数 [英] TypeError: jQuery(...).ready(...) is not a function
问题描述
好的,我知道之前已经问过这个问题但是没有一个答案似乎适用于我的情况。我正在尝试运行一小段jQuery(我刚开始使用它)。
OK, I know this has been asked before but none of the answers seems to apply to my case. I'm trying to get a very tiny piece of jQuery running (I'm just getting started on it).
jQuery(document).ready(function(){
jQuery('.comtrig').on('click',function(){
$(this).next().animate({'display':'inline'},1000);
});
})();
我收到错误 TypeError:jQuery(...)。ready( ...)不是FF中的函数
或未知的TypeError:对象不是Chrome中的函数
。
- 解决方案1是用
jQuery
替换$
但是我显然已经如上所示那样做了 - 我不在Wordpress中
- 我只使用jQuery和上面的迷你脚本,没有别的JS
- jQuery本身好像加载好了
- Solution 1 was to replace
$
withjQuery
but I obviously already did that as shown above - I'm not in Wordpress either
- I'm using only jQuery and the above mini script, no other JS
- jQuery itself seems to load fine
我在这里缺少什么?
推荐答案
尝试在doc ready结束时删除此();
:
try to remove this ();
at the end of doc ready:
jQuery(document).ready(function(){
jQuery('.comtrig').on('click',function(){
$(this).next().animate({'display':'inline'},1000);
});
}); //<----remove the (); from here
();
通常使用有一个立即调用的函数表达式(IIFE),它有这样的语法:
();
is normally used to have a Immediately-Invoked Function Expression (IIFE) which has some kind of syntax like this:
(function(){
// your stuff here
})(); //<----this invokes the function immediately.
您的错误:
Your errors:
in firefox = TypeError:jQuery(...)。ready(...)不是函数
in firefox = TypeError: jQuery(...).ready(...) is not a function
in chrome = 未捕获TypeError:对象不是函数
in chrome = Uncaught TypeError: object is not a function
因为:
您的文档就绪处理程序不是自执行匿名函数。
Your document ready handler is not a Self-executing anonymous function.
这篇关于TypeError:jQuery(...)。ready(...)不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!