2012-04-28 131 views
0

如何獲取setTimeout中的$(this)以獲取懸停函數的選擇器,在img以下的情況下。jQuery,獲取外部函數選擇器

$("img").hover(function(){ 
window.setTimeout(function() { 
    $(this).addClass("hovering"); // add class .hovering to the exact img being hovered 
}, 500); 
}); 

回答

1

this放在其他變量中。

$("img").hover(function() { 
    var $this = $(this); 

    window.setTimeout(function() { 
     $this.addClass("hovering"); // add class .hovering to the exact img being hovered 
    }, 500); 
}); 
+0

@RepWhoringPeeHaa:停止用修辭問題抨擊我的不當術語! :) – Ryan 2012-04-28 15:46:54