我遇到这个错误
Uncaught ReferenceError: $ is not defined.
我进行了搜索,发现造成这种情况的通常原因是没有在正确的位置声明 jQuery,但我认为我是对的。
提前致谢。
<script type="text/javascript" src="jquery-1.2.6.min.js"></script>
<script type="text/javascript" src="ajax2.js"></script>
<script type="text/javascript">
var slideimages = new Array() // create new array to preload images
slideimages[0] = new Image() // create new instance of image object
slideimages[0].src = "images/aib.jpg" // set image src property to image path, preloading image in the process
slideimages[1] = new Image()
slideimages[1].src = "images/paddypower.jpg"
slideimages[2] = new Image()
slideimages[2].src = "images/rtegaa.jpg"
slideimages[3] = new Image()
slideimages[3].src = "images/ssgaa.jpg"
$(document).ready(function(){
function get_weather()
{
var p = $("#code").val();
var u = ($('#u').attr('checked')) ? '&u=c' : '';
var to_load = 'get_weather.php?p='+ p + u;
$("#weather").html('<img style="margin-top: 104px;" src="ajax-loader.gif" align="absmiddle">');
$("#weather").load(to_load);
}
$(window).load(get_weather); // Trigger "get_weather" when the window loads
// Trigger "get_weather" when the form objects are used
$("#code").change(get_weather);
$("#u").click(get_weather);
});
最佳答案
解决办法:
1)使用Google CDN加载jQuery
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
2) 它与 jQuery v1.5-v1.7 兼容,因为大多数方法在 jQuery 1.8+ 中已被弃用。这就是我在第 1 点中使用 v1.5 的 Google CDN jquery 的原因。大多数关于 Cycle 插件的示例都使用 jquery 1.5。
3)清除浏览器缓存,大多数时候它是罪魁祸首。
4)请使用下面的代码检查jquery的加载情况
if(typeof jQuery!=='undefined'){
console.log('jQuery Loaded');
}
else{
console.log('not loaded yet');
}
关于javascript - Uncaught ReferenceError : $ is not defined Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30097870/