JavaScript Uncaught ReferenceError: jQuery is not defined; 未捕获的 ReferenceError: $ 未定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24946616/
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
JavaScript Uncaught ReferenceError: jQuery is not defined; Uncaught ReferenceError: $ is not defined
提问by Soo
This is my fiddle, http://jsfiddle.net/4vaxE/35/
这是我的小提琴,http://jsfiddle.net/4vaxE/35/
It work fine in my fiddle.
它在我的小提琴中工作正常。
However, when I transfer it to dreamweaver, it can't work. And I found this two error in my coding.
但是,当我将其传输到 Dreamweaver 时,它无法工作。我在编码中发现了这两个错误。
- Uncaught ReferenceError: jQuery is not defined
- uncaught referenceerror $ is not defined
- 未捕获的 ReferenceError:未定义 jQuery
- 未捕获的引用错误 $ 未定义
I had read before the article related to this two error, and tried to solve according to the method provided, however, it still not working, how can I solve this?
之前看过关于这两个错误的文章,按照提供的方法尝试解决,但是还是不行,请问怎么解决呢?
Here is my full coding in dreamweaver
这是我在 Dreamweaver 中的完整编码
<body>
<div class="buttons" style="background-color: rgba(0,0,0,.8);">
<a class="button" id="showdiv1">Div 1</a>
<a class="button" id="showdiv2">Div 2</a>
<a class="button" id="showdiv3">Div 3</a>
<a class="button" id="showdiv4">Div 4</a>
</div>
<div id="div1">1</div>
<div id="div2">2</div>
<div id="div3">3</div>
<div id="div4">4</div>
</div>
<script language="JavaScript" type="text/javascript" script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/jquery-ui.min.js"></script>
<script language="JavaScript" type="text/javascript">
var selectedEffect="explode";
var options = { percent: 100 };
$('#showdiv1').click(function () {
$('div[id^=div]').hide();
$('#div1').show( selectedEffect, options, 500, callback );
});
$('#showdiv2').click(function () {
$('div[id^=div]').hide();
$('#div2').show( selectedEffect, options, 500, callback );
});
$('#showdiv3').click(function () {
$('div[id^=div]').hide();
$('#div3').show( selectedEffect, options, 500, callback );
});
$('#showdiv4').click(function () {
$('div[id^=div]').hide();
$('#div4').show( selectedEffect, options, 500, callback );
});
function callback() {
setTimeout(function() {
$( "#effect:visible" ).removeAttr( "style" ).fadeOut();
}, 1000 );
};
</script>
</body>
</html>
CSS
CSS
<style type="text/css">
.button {
cursor:pointer;
display:inline-block;
margin:10px;
clip: rect(auto,auto,auto,auto);
}
#div1 {
background:aqua;
padding:20px;
width:100px;
text-align:center;
display:none;
}
#div2 {
background:blue;
padding:20px;
width:100px;
text-align:center;
display:none;
}
#div3 {
background:orange;
padding:20px;
width:100px;
text-align:center;
display:none;
}
#div4 {
background:green;
padding:20px;
width:100px;
text-align:center;
display:none;
}
a {
color:aqua;
-webkit-filter: grayscale(1.0);
}
a:hover {
color:red;
-webkit-filter: grayscale(0.0);
}
</style>
回答by Roko C. Buljan
Cause you need to add jQuery library to your file:
因为您需要将 jQuery 库添加到您的文件中:
jQuery UI is just an addon to jQuerywhich means that
first you need to include the jQuerylibrary → and then the UI.
jQuery UI 只是jQuery 的一个插件,这意味着
首先你需要包含jQuery库 → 然后是UI。
<script src="path/to/your/jquery.min.js"></script>
<script src="path/to/your/jquery.ui.min.js"></script>
回答by sun_dare
You did not include jquery library. In jsfiddle its already there. Just include this line in your head section.
您没有包含 jquery 库。在 jsfiddle 中它已经存在了。只需将此行包含在您的头部部分即可。
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
回答by Jo?o Pinho
You have an error in you script tag construction, this:
您在脚本标记构造中出错,这是:
<script language="JavaScript" type="text/javascript" script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/jquery-ui.min.js"></script>
Should look like this:
应该是这样的:
<script language="JavaScript" type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/jquery-ui.min.js"></script>
You have a 'script' word lost in the middle of your script tag. Also you should remove the http:// to let the browser decide whether to use HTTP or HTTPS.
您的脚本标签中间丢失了一个“脚本”字样。此外,您应该删除 http:// 以让浏览器决定是使用 HTTP 还是 HTTPS。
UPDATE
更新
But your main error is that you are including jQuery UI (ONLY) you must include jQuery first! jQuery UI and jQuery are used together, not in separate. jQuery UI depends on jQuery. You should put this line before jQuery UI:
但是您的主要错误是您包含 jQuery UI(仅)您必须首先包含 jQuery!jQuery UI 和 jQuery 一起使用,而不是分开使用。jQuery UI 依赖于 jQuery。您应该将此行放在 jQuery UI 之前:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>