2012-07-09 32 views
0

您好我有mouseenter和ajax触发器的问题。如果我将注意力集中在1秒钟的对象上,我想触发ajax。如果我离开对象,它不应该触发ajax事件。Mouseenter和AJAX事件 - JQUERY

$('.popHover').mouseenter(function(e){ 
    setTimeout(function(){ 
    // ajax event here and pophover will show 
    },1000) 
}).mouseout(function(e){ 
    // close pophover 
}) 

回答

0

您可以使用clearTimeout

var timeout_id; 

$('.popHover').mouseenter(function(e){ 
    timeout_id = setTimeout(function(){ 
    // ajax event here and pophover will show 
    },1000); 
}).mouseout(function(e){ 
    // close pophover 
    clearTimeout(timeout_id); 
}); 
+0

谢谢。问题解决了。 – Jingcleovil 2012-07-09 07:02:33