Javascript 未捕获的类型错误:对象 [对象 DOMWindow] 的属性“$”不是函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6992723/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 00:10:46  来源:igfitidea点击:

Uncaught TypeError: Property '$' of object [object DOMWindow] is not a function

javascriptjquery

提问by Jasper

I am getting an : Uncaught TypeError: Property '$' of object [object DOMWindow] is not a functionerror in Chrome with my script.

我得到一个:未捕获的类型错误:对象 [object DOMWindow] 的属性 '$' 不是Chrome 中我的脚本的函数错误。

<script type="text/javascript"> 
    function showSlidingDiv() {
        $("#slidingDiv").fadeToggle("slow", "linear");
    }
    function showSlidingDiv2() {
        $("#slidingDiv2").fadeToggle("slow", "linear");
    }         
    function showSlidingDiv3() {
        $("#slidingDiv3").fadeToggle("slow", "linear");
    }
</script> 

Does anyone know what could be wrong here?

有谁知道这里可能有什么问题?

回答by sanusi

Chrome does load other libraries that make the use of $ symbol on other purposes, so you have to use jquery no conflict. on of the way is to change the $ symbol with jQuery

Chrome 确实加载了将 $ 符号用于其他目的的其他库,因此您必须使用 jquery 没有冲突。方法是用 jQuery 更改 $ 符号

$(function(){...});

change to

改成

jQuery(function(){...});

回答by petho

My guess is that jquery was not loaded before run of one of these methods, so or it's not included before run of these methods, or there's some error causing it to not load properly. Normally this should "just work" (at least not throw that kind of error message)

我的猜测是 jquery 在运行这些方法之一之前没有加载,所以或者在运行这些方法之前没有包含它,或者有一些错误导致它无法正确加载。通常这应该“正常工作”(至少不会抛出那种错误消息)

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript"> 
    function showSlidingDiv() {
        $("#slidingDiv").fadeToggle("slow", "linear");
    }
    function showSlidingDiv2() {
        $("#slidingDiv2").fadeToggle("slow", "linear");
    }         
    function showSlidingDiv3() {
        $("#slidingDiv3").fadeToggle("slow", "linear");
    }
</script> 

回答by George

No mather the time.. I found a solution that worked for me.

没有时间......我找到了一个对我有用的解决方案。

Instead of

代替

$("#slidingDiv")

try

尝试

jQuery("#slidingDiv")

the other options weren′t usefull for me.

其他选项对我没有用。

回答by Rameez SOOMRO

<script type="text/javascript"> 
var j = jQuery;
function showSlidingDiv() {
    j("#slidingDiv").fadeToggle("slow", "linear");
}
function showSlidingDiv2() {
    j("#slidingDiv2").fadeToggle("slow", "linear");
}         
function showSlidingDiv3() {
    j("#slidingDiv3").fadeToggle("slow", "linear");
}
</script> 

回答by ContextSwitch

make sure jQuery.noConflict() isn't being called. Calling it won't allow the use of the $ shorthand notation.

确保 jQuery.noConflict() 没有被调用。调用它不允许使用 $ 速记符号。