2011-10-18 107 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,因为该方法提供了更多的控制,通常是比较合适的。