未捕获的ReferenceError:“$未定义” [英] Uncaught ReferenceError: "$ is not defined"
问题描述
这是我在因特网上发现的一个工具提示js函数,并且由于防御性编程而对其重新编码。但原始代码和我的代码具有相同的Google Chrome控制台控制台错误消息。
消息说:
未捕获的ReferenceError:未定义$。
该错误正在为以下行生成。
$(document).ready(function(){...
代码工作正常,没有bug。在主函数中,控制台没有给出 $
标志的错误信息。
一个例子:
$(document).ready(函数(){... //在控制台上没有错误$
Chrome浏览器控制台的错误还是我的错?
this.tooltip = function(){
/ * CONFIG * /
xOffset = 10;
yOffset = 20;
//这两个变量确定弹出窗口与光标的距离
//您可能需要调整以获取th e正确结果
/ * END CONFIG * /
$(a.tooltip)。hover(function(e){
if(this.t)
this.t = this.title;
this.title =;
$(body)。append(< p id ='tooltip'>+ this.t +< / p>);
$(#tooltip)
.css(top,(e.pageY - xOffset)+px)
.css(left,(e.pageX + yOffset)+px)
.fadeIn(fast);
},
function(){
this.title = this.t;
$(#tooltip)。remove();
});
$(。tooltip)。mousemove(function(e){
$(#tooltip)
.css(top,(e.pageY - xOffset)+ px)
.css(left,(e.pageX + yOffset)+px);
});
};
$ b $(document).ready(function(){
tooltip();
});
您是否顺序/正确地调用JavaScript文件? / p>
例如
< script type =text / javascript SRC = 的jquery.js >< /脚本>
< script type =text / javascriptsrc =main.js>< / script>
它可能与您在文档标题中调用JavaScript的方式有关声音。
根据您的评论,我刚刚看到... Main.js必须是AFTER jquery.js。
This is a tooltip js function that I found on the internet and re-coded it due to defensive programming. But the orginal code and my code have same Google Chrome Console Error Message.
Message says:
Uncaught ReferenceError: $ is not defined.
The error is generating for the following line.
$(document).ready(function(){...
The code is working fine without a bug. In the main function, the console is not giving an error message for $
signs.
An example:
$(document).ready(function(){... //no error on console for "$"
So, Is this a bug of Chrome Browser's Console Or is it my fault?
this.tooltip = function(){
/* CONFIG */
xOffset = 10;
yOffset = 20;
// these 2 variable determine popup's distance from the cursor
// you might want to adjust to get the right result
/* END CONFIG */
$("a.tooltip").hover(function(e){
if (this.t)
this.t = this.title;
this.title = "";
$("body").append("<p id='tooltip'>"+ this.t +"</p>");
$("#tooltip")
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px")
.fadeIn("fast");
},
function(){
this.title = this.t;
$("#tooltip").remove();
});
$(".tooltip").mousemove(function(e){
$("#tooltip")
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px");
});
};
$(document).ready(function(){
tooltip();
});
Are you calling your JavaScript files sequentially/ correctly?
For instance
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="main.js"></script>
it has something to do probably with the way you are calling your javascript in the header of your document it sounds.
Based on your comment I just saw... Main.js must be AFTER jquery.js.
这篇关于未捕获的ReferenceError:“$未定义”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!