Firefox中的ClientX和ClientY引用错误?

时间:2014-02-25 06:26:46

标签: javascript jquery html css firefox

我有一个简单的jquery程序,其中div应该基于坐标显示  鼠标悬停评论。我使用了event.clientX和event.clientY函数,遗憾的是这些函数在firefox浏览器中不起作用(firefox中的错误是“ReferenceError:event not defined”)。适用于Chrome和IE。请帮助。谢谢。

<div class="comment"></div>
<div class="commentBox">
 <p>welcome</p>
 </div>

$('.comment').hover(function(e){

     var x=event.clientX
 var y=event.clientY
  x=x-263;

$('.commentBox').css({"left":x+"px","top":y+"px"});


    $('.commentBox').css('visibility','visible');

    },function(e){


        $('.commentBox').css('visibility','visible');
  });

1 个答案:

答案 0 :(得分:0)

$('.comment').hover(function(e){

     var x=e.clientX;//replaced event with e
     var y=e.clientY;////replaced event with e

您有参数e而不是event。所以你得到ReferenceError: event is not defined