2017-10-06 76 views

回答

1

您可能想要使用setTimeout來延遲函數的執行。

function countdown(time){ 
    if (time>0){ 
     console.log(time); 
     setTimeout(function(){countdown(time-1)},1000); 
     }else{ 
      console.log("GO");// replace with any function 
     }; 
} 
countdown(3); 
+0

「延遲」和「倒數」不是同一回事。 – nnnnnn

+0

非常感謝。這幫助了我。 – ria

+0

@nnnnnn:倒計時只不過是延遲時間提示,因爲沒有提供關於UI的信息,所以假設OP想要延遲該函數是安全的。 – dolphin