jQuery mouseover和mouseout错误 [英] jquery mouseover and mouseout bug
问题描述
当我将鼠标悬停在某个元素上(以查看包含该元素的整体数据)并且推出所有内容时,我正在尝试预览某些内容.问题是当我快速移动鼠标光标时,有时没有发生mouseout方法,并且数据保持更新,而我不希望那样.知道我该怎么做吗?
I am trying to get a preview of something when i roll over an element ( to see the overall data with that element included) and when I roll out everything is back as it was. The problem is when I move the mouse cursor quick sometimes the mouseout method is not happening and the data remains updated and I dont want that. Any idea how I can do this ?
$(document).on("mouseover", ".checkRezolvata", function(e){
var idTemp = "";
idTemp = $(this).parent().parent().parent().attr("id");
data = {
id: idTemp,
set: 1 }
$.ajax({
type: "POST",
url: "crm/setRezolvataTemp.php",
data: data,
async: false,
success: function(data){
if(data == 1) {
getStats();
getTarget();
} else
alert("Eroare la schimbarea starii crmului temp!");
},error: function(){
alert("eroare");
}
});
});
$(document).on("mouseout", ".checkRezolvata", function(){
var idTemp = "";
idTemp = $(this).parent().parent().parent().attr("id");
data = {
id: idTemp,set: 0}
$.ajax({
type: "POST",
url: "crm/setRezolvataTemp.php",
data: data,
async: false,
success: function(data){
if(data == 1) {
getStats();
getTarget();
} else
alert("Eroare la schimbarea starii crmului temp!");
},error: function(){
alert("eroare");
}
});
});
推荐答案
您可以在jQuery中尝试mouseenter
和mouseleave
事件处理程序. mouseover
和mouseout
通常很棘手,另请参见:
You can try the mouseenter
and mouseleave
event handlers in jQuery. mouseover
and mouseout
is very often a bit tricky, see also:
http://api.jquery.com/mouseenter/
http://api.jquery.com/mouseleave/
mouseenter事件与mouseover的不同之处在于它处理事件冒泡的方式.如果在此示例中使用mouseover,则当鼠标指针移到Inner元素上时,将触发处理程序.这通常是不受欢迎的行为.另一方面,mouseenter事件仅在鼠标进入绑定到的元素而不是后代时才触发其处理程序.因此,在此示例中,当鼠标输入Outer元素而不是Inner元素时触发处理程序.
The mouseenter event differs from mouseover in the way it handles event bubbling. If mouseover were used in this example, then when the mouse pointer moved over the Inner element, the handler would be triggered. This is usually undesirable behavior. The mouseenter event, on the other hand, only triggers its handler when the mouse enters the element it is bound to, not a descendant. So in this example, the handler is triggered when the mouse enters the Outer element, but not the Inner element.
这篇关于jQuery mouseover和mouseout错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!