2011-10-18 106 views
1

這裏是我們的代碼:兩個jQuery延遲消息?

<script type="text/javascript"> 
$(document).ready(function() { 
    $('a#installfc').click(function(e){ 
     e.preventDefault(); 
     window.open("http://www.site.com/ads/tr.php?src=source",'_parent');  
     $(this).html("Opening Download Link.. Please wait").delay(3000).html("Please run the installer after downloading"); 
    }); 
}); 
</script> 

基本上,我們希望消息顯示,然後3秒後它變成另一條消息。

我在做什麼錯?

〜jquery noob。

+0

我認爲延遲隻影響動畫隊列,它不是阻塞呼叫。 – Lazarus

回答

2

香港專業教育學院只有真正看到使用delay做jQuery的動畫效果時。它可能存在使用該方法做你想做什麼辦法,但你可以很容易地回落到標準的JavaScript setTimeout

活生生的例子:http://jsfiddle.net/TMgPD/

$('a#installfc').click(function(e){ 
     e.preventDefault(); 
     window.open("http://www.site.com/ads/tr.php?src=source");  
     $this = $(this); 
     $this.html("Opening Download Link.. Please wait") 
     setTimeout(function(){ 
        $this.html("Please run the installer after downloading") 
     },3000); 
    }); 
1

改用setTimeOut函數

2

改爲使用setTimeout。延遲僅適用於jQuery的影響(例如slidUp,淡入):

$(this).html("Opening Download Link.. Please wait"); 
    setTimeout(function() { 
     $(this).html("Please run the installer after downloading"); 
    }, 3000); 
0

您可以使用延遲隊列一起得到你想要的效果。

$(this).html("Text 1").delay(3000).queue(function(next) { 
    $(this).html("Text 2"); 
    next(); 
}); 

一般情況下,我想你會要堅持的setTimeout,因爲該方法提供了更多的控制,通常是比較合適的。