2011-05-08 29 views
1

我想按fadeOut一個按鈕,然後fadeIn響應一個Ajax調用。響應是一個新的按鈕。但是,下面的代碼是第一個按鈕,然後將其淡入,然後將其替換爲新的。我嘗試了幾種組合,但無法使其工作。我哪裏做錯了?jQuery的效果順序問題

beforeSend: function() 
{ 
    $(this).fadeOut("slow"); 
}, 

success: function(response) 
{ 
    $(this).fadeIn("slow", function() { 
     $(this).parent().html(response); 
    }); 
} 

回答

3

this AJAX調用裏面不是一個元素了。你必須將它存儲到AJAX調用之前的一個變種,如:

var button = $(this);

及更高版本:

button.fadeOut();

等。

1

試試這個(注意淡出的輸入錯誤 「秀」):

beforeSend: function() 
{ 
    $(this).fadeOut("slow"); 
}, 

success: function(response) 
{ 
    $(this).parent().html(response); 
    $(this).stop().fadeIn("slow"); 
} 
1

$(this).parent().html(response);將有效消除this。因此,將其更改爲這應該修復它:

$(this).parent().html(response); 
$("#thething").stop().fadeIn("slow"); 

其中#thething是「本」

編輯的ID:還什麼morgar說。