2010-07-14 83 views
0

我試圖在$('div')。fadeOut()回調中設置目標A tag時遇到了一些問題。AJAX請求和這個

我得到這個

$('.anchor').click(function() { 
    $('#div').fadeOut(null, showDiv); 
    $('#div').fadeIn(); 
    return false; 
}); 

showDiv是一個Ajax請求,我用$(this)裏面試圖指點擊A tag,但我注意到,它是指div #div

我想要做的是當點擊一個link時做一些AJAX請求,但我希望它只在DIV淡出後發生。這樣,請求將填充#div,新內容只會在其再次淡入時顯示。

回答

1

您可以更改使用$.proxy()的背景下,這樣的:

$('.anchor').click(function() { 
    $('#div').fadeOut(null, $.proxy(showDiv, this)); 
    $('#div').fadeIn(); 
    return false; 
}); 

You can test it here,或者手動做同樣的事情:

$('.anchor').click(function() { 
    var self = this; 
    $('#div').fadeOut(null, function() { 
    showDiv.apply(self); 
    }); 
    $('#div').fadeIn(); 
    return false; 
});