admin管理员组文章数量:1404927
I'm trying to get the example code in this SO question running on my system
getting the X/Y coordinates of a mouse click on an image with jQuery
It displays the position of the mouse on a click inside a div
. It works fine on Firefox
and Safari
but doesn't update on Chrome
and I'm wondering if I've done something wrong.
I'm using Google Chrome Version 23.0.1271.101
Here's the code I'm using.
<html>
<head>
<script class="jsbin" src=".9.0/jquery.min.js"></script>
</head>
<body>
<p>Click to see the position!</p>
<div class="box" style="width: 200px; height: 200px; background: #F00"> </div>
<p id="position">Position will go here</p>
<script>
$(document).ready(function() {
$('.box').click(function(e) {
var offset = $(this).offset();
$('#position').html(Math.round(e.clientX - offset.left) + ", " + Math.round(e.clientY - offset.top));
});
});
</script>
</body>
</html>
Update:
Here is the error I see on Chrome's JavaScript console Uncaught ReferenceError: $ is not defined
but I'm not sure what to make of it.
Update2:
I cleared the browser cache and reloaded the page while having the JavaScript console open and noticed an error I had not seen before
[blocked] The page at https://<mywebsite>/index.html ran insecure content from .9.0/jquery.min.js.
Uncaught ReferenceError: $ is not defined
So, I downloaded jquery.min.js
and placed it in the same directory as index.html
and changed the loading of the script to
<script src="./jquery.min.js" type="text/javascript"></script>
It now works on all three browsers.... so for some reason Chrome was the only one that plained about the url for jquery.min.js being insecure. To pound the problem, it didn't give me that error when I went into the JavaScript console, and I didn't see it until I had cleared the cache and I had the JavaScript console open.
I'm trying to get the example code in this SO question running on my system
getting the X/Y coordinates of a mouse click on an image with jQuery
It displays the position of the mouse on a click inside a div
. It works fine on Firefox
and Safari
but doesn't update on Chrome
and I'm wondering if I've done something wrong.
I'm using Google Chrome Version 23.0.1271.101
Here's the code I'm using.
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis./ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>
<p>Click to see the position!</p>
<div class="box" style="width: 200px; height: 200px; background: #F00"> </div>
<p id="position">Position will go here</p>
<script>
$(document).ready(function() {
$('.box').click(function(e) {
var offset = $(this).offset();
$('#position').html(Math.round(e.clientX - offset.left) + ", " + Math.round(e.clientY - offset.top));
});
});
</script>
</body>
</html>
Update:
Here is the error I see on Chrome's JavaScript console Uncaught ReferenceError: $ is not defined
but I'm not sure what to make of it.
Update2:
I cleared the browser cache and reloaded the page while having the JavaScript console open and noticed an error I had not seen before
[blocked] The page at https://<mywebsite>/index.html ran insecure content from http://ajax.googleapis./ajax/libs/jquery/1.9.0/jquery.min.js.
Uncaught ReferenceError: $ is not defined
So, I downloaded jquery.min.js
and placed it in the same directory as index.html
and changed the loading of the script to
<script src="./jquery.min.js" type="text/javascript"></script>
It now works on all three browsers.... so for some reason Chrome was the only one that plained about the url for jquery.min.js being insecure. To pound the problem, it didn't give me that error when I went into the JavaScript console, and I didn't see it until I had cleared the cache and I had the JavaScript console open.
Share Improve this question edited May 23, 2017 at 12:28 CommunityBot 11 silver badge asked Mar 10, 2013 at 22:46 amdnamdn 11.6k36 silver badges45 bronze badges1 Answer
Reset to default 4The error you are getting is that jQuery is not loaded when executing your script. So therefore $ is not defined when you try to use it.
Also, your screenshot is not showing the same markup as your example.
本文标签:
版权声明:本文标题:javascript - "Uncaught ReferenceError: $ is not defined" error on Google Chrome (but works on Firefox and Safa 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744875662a2629900.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论