我在页面中有一个图像,在该图像的onmouseover
事件中,我将调用JavaScript函数来显示工具提示,而在图像的onmouseout
中,我将调用一个方法来隐藏工具提示。现在我发现,当我将光标放在图像上时,它会调用显示工具提示div的方法。
如果我在图像中移动鼠标,它将调用onmouseout
事件(即使我没有离开图像)。我怎么才能阻止它呢?我希望在光标离开图像时调用onmouseout
。有什么想法吗?
我是这样称呼它的:
<img src="images/customer.png" onmouseout="HideCustomerInfo()" onmouseover="ShowCustomerInfo(485)" />
在我的JavaScript中:
function ShowCustomerInfo(id) {
var currentCustomer = $("#hdnCustomerId").val();
if (currentCustomer != id) { // to stop making an ajax call everytime when the mouse move on the same image
$.get('../Lib/handlers/userhandler.aspx?mode=custinfo&cid=' + id, function (data) {
strHtml = data;
});
tooltip.show(strHtml); // method in another jquery pluggin
$("#hdnCustomerId").val(id);
}
}
function HideCustomerInfo() {
tooltip.hide(); // method in another jquery pluggin
$("#hdnCustomerId").val(0); //setting in a hidden variable in the page
}
发布于 2010-09-28 00:23:48
我猜你是在工具提示上移动鼠标吧?并且工具提示的标记超出了图像的范围?
因此,通过将鼠标放在工具提示上,从技术上讲,您离开了图像。我也遇到过类似的事情。
要解决此问题,请尝试在图像周围粘贴div
,并将鼠标事件放在div
上,然后作为div
的子元素使用您的工具提示,因此即使您将鼠标悬停在工具提示上,您仍然处于div
内部。
这可能行得通。
发布于 2013-03-26 01:58:42
如果你用来悬停的图片是透明的(对吧,它是一个png ),那么当你把鼠标移到图片的透明部分时,你会得到一个onmouseout事件。是啊,糟透了。我也有同样的问题,但目前还没有完美的解决方案。
发布于 2020-09-30 10:10:45
解决此问题的另一种简单方法是在工具提示上设置pointer-events: none
https://stackoverflow.com/questions/3805736
复制相似问题