簡體   English   中英

jQuery等待函數執行

[英]jQuery wait till function is executed

我正在嘗試調用2個函數。 第一個函數包括jQuery效果。 第二個函數(在這種情況下是jQuery效果),但只能在第一個函數執行(並完成)時執行。 有人可以幫我嗎? 謝謝!

福克斯的例子: http//jsfiddle.net/fNH2u/1/

function hideSecond(){
    $("#second").hide("slow");
}

$("#first").click(function(){
    hideSecond();
    $(this).hide("fast");
});

和HTML:

<div id="first">
    first
</div>
<div id="second">
    second
</div>

我想調用的函數不僅僅是jQuery效果。 這只是一個例子。 把這兩個功能放在一起並不是我真正想要的。

您需要在此處使用回調。

function hideSecond(callback){
    $("#second").hide("slow", callback);
}

$("#first").click(function(){
    hideSecond(function() {
       $(this).hide("slow");
    });
});

嘗試在[complete]參數中使用.animate()和回調函數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM