2012-03-30 77 views
1

我無法獲得一些JavaScript和Jquery來延遲適當的時間。我想更改一些文字,等待5秒鐘,然後彈出提醒。正在跳過JQuery延遲()函數

下面的代碼:

$('#result').html("Record has passed").delay(5000); 
alert("Record has passed"); 

出於某種原因,該警報運行jQuery的改變#result和等待了。任何解決方案或任何其他人看到這個問題?

我已經試過

setTimeout($('#result').html("Record has passed"), 5000); 

很好,但仍然沒有運氣。

+0

我還要補充一點,我已經試過移動.delay(5000),以及: $(「#結果」 ).delay(5000).html(「Record has passed」); – Proxy404 2012-03-30 18:58:50

回答

3

jQuery的.delay方法僅適用於動畫和排隊功能。請嘗試使用setTimeout

$("#result").html("Record has passed"); 
setTimeout(function(){ 
    alert("Record has passed"); 
},5000); 
1
$('#result').html("Record has passed"); 
setTimeout(function(){ 
    alert("Record has passed"); 
},5000);​ 

Example Here

1

如果你仍然想使用jQuery的延遲,美國可以這樣做:

$('#result').html("Record has passed").delay(5000).queue(function() { 
    alert("Record has passed"); 
});