Javascript 未捕获的类型错误:对象 [object global] 的属性“$”不是函数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2079115/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uncaught TypeError: Property '$' of object [object global] is not a function?
提问by Olivers
I am getting the following error
我收到以下错误
Uncaught TypeError: Property '
$' of object [object global] is not a function in line 2:
未捕获的类型错误:
$对象 [object global] 的属性“ ”不是第 2 行中的函数:
Using the following code:
使用以下代码:
$(document).ready(function() {
$('#tabs > ul').tabs({ fx: { opacity: 'toggle' } });
$('#featuredvid > ul').tabs();
});
The problem appears local at 127.0.0.1 only, while same code OK online! I'm dazzled, any ideas?
问题只在127.0.0.1本地出现,同码在线即可!我眼花缭乱,有什么想法吗?
回答by simoes
I ran into this error when I was trying to use the slide effectthat I thought was part of jQuery but was actually a jQuery UI effect. This was the output from my console:
当我尝试使用我认为是 jQuery 的一部分但实际上是 jQuery UI 效果的幻灯片效果时,我遇到了这个错误。这是我的控制台的输出:
Uncaught TypeError: Property '#<Object>' of object #<Object> is not a function
So, to me it seems like you just need to include the jquery UI library. Add this line after you include jQuery.
所以,对我来说,你似乎只需要包含 jquery UI 库。在包含 jQuery 后添加此行。
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
回答by bunnyhero
Check to see if any other script you are using is calling jQuery.noConflict(). Doing so releases the $binding, thus causing the $symbol to be undefined.
检查您正在使用的任何其他脚本是否正在调用jQuery.noConflict()。这样做会释放$绑定,从而导致$符号未定义。
One way to fix this is to add $as the first parameter of your callback function:
解决此问题的一种方法是将其添加$为回调函数的第一个参数:
$(document).ready(function($) {
...
}
This works because the global jQuery object is passed as the first parameter to a .ready()handler. See also http://api.jquery.com/ready/
这是有效的,因为全局 jQuery 对象作为第一个参数传递给.ready()处理程序。另见http://api.jquery.com/ready/
回答by andrhamm
Use this instead:
改用这个:
jQuery(document).ready(function($){
$('#tabs > ul').tabs({ fx: { opacity: 'toggle' } });
$('#featuredvid > ul').tabs();
});
回答by flyin23
I had pretty much same problem. The error message says
我有几乎同样的问题。错误消息说
TypeError: $ is not a function
$(document).ready(function() {
The line in my code that was throwing error is this :
我的代码中抛出错误的行是这样的:
$(document).ready(function(){
In my case the problem is that $ is not recognized as jquery. I had to replace $ with the keyword jQuery. So finally i changed my code like this:
在我的情况下,问题是 $ 不被识别为 jquery。我不得不用关键字 jQuery 替换 $。所以最后我像这样改变了我的代码:
jQuery(document).ready(function(){
And it worked.
它奏效了。
回答by reign85
I got the same error and solve it by adding
我遇到了同样的错误并通过添加来解决它
var $ = jQuery;
as a global var on my script
作为我脚本上的全局变量
回答by Stoinov
I had the same error with tabs and after some digging in jQuery documentation I found this: http://docs.jquery.com/Using_jQuery_with_Other_Libraries#Overriding_the_.24-function
我在选项卡上遇到了同样的错误,在对 jQuery 文档进行了一些挖掘之后,我发现了这个:http: //docs.jquery.com/Using_jQuery_with_Other_Libraries#Overriding_the_.24-function
Once I overrode the jQuery it was working. So it seems like I had some namespace problems.
一旦我覆盖了 jQuery,它就可以工作了。所以看起来我有一些命名空间问题。
回答by Gabriele Petrioli
Is jquery available locally ? (the error you mention usually means that the jQuery is not available - loaded)
jquery 在本地可用吗?(您提到的错误通常意味着 jQuery 不可用 - 已加载)
Perhaps you are loading it from a relative path and the structure is different to the online version ..
也许您是从相对路径加载它并且结构与在线版本不同..
回答by adamJLev
Might be a browser security setting, blocking JS to run locally, are you using IE by any chance? Try with Firefox or play with your security settings in IE
可能是浏览器的安全设置,阻止JS在本地运行,你用IE吗?尝试使用 Firefox 或在 IE 中使用您的安全设置
回答by Abdennour TOUMI
Simply, use the following :
简单地,使用以下内容:
jQuery(function() {
//Your code when document will be ready
});
回答by Massimo Fazzolari
Disabling the pop up blocker worked for me
禁用弹出窗口拦截器对我有用

