2014-12-04 39 views
0

我得到數據並將它們設置爲標記後,5秒後我想清除此標記。我嘗試:5秒後刪除內容窗體標記

$('#ajax_message').html(data).delay(5000).html(""); 

但這不工作。我該怎麼做?

回答

4

按照Doc:

jQuery.delay()是最好的排隊jQuery效果和這樣之間延遲,並且是沒有爲JavaScript的本機setTimeout函數的替代,其可以是更適合於某些使用情況。

長話短說,.delay()作品queued functions。您應該使用setTimeout()

$('#ajax_message').html(data) 
setTimeout(function(){ 
    $('#ajax_message').html(""); 
},5000); 
0

我解決這個問題:

window.setTimeout(function() { 
    $('#ajax_message').html(''); 
}, 5000); 
+1

使用'window.setTimeout()'如果你要執行一次,'setInterval'將遍歷每個5秒 – Girish 2014-12-04 10:21:36