2012-02-10 167 views
0

这是一个工具提示js函数,我在因特网上找到并重新编码它,因为防御性编程。但原始代码和我的代码具有相同的Google Chrome控制台错误消息。

消息表示:

Uncaught ReferenceError: $ is not defined.

的误差产生用于下面的行。

$(document).ready(function(){... 

该代码工作正常,没有bug。在主要功能中,控制台未给出$标志的错误消息。

一个例子:

$(document).ready(function(){... //no error on console for "$" 

所以,这是Chrome的浏览器的控制台或者一个错误是我的错吗?

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(); 
}); 
+1

因此,您在控制台中看到'$未定义',但代码正常工作? – 2012-02-10 15:55:06

+0

是的...这个代码在main.js中。我从我的HTML中调用它; * \t

0

你在添加jQuery吗?也许听起来很愚蠢,但用你提供的代码没有什么可以阻止jQuery。