jQuery 定时事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2208626/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery Timed Event
提问by George Johnston
Is it possible, using jQuery, to fire off an event to set a div tag's text after n. seconds?
是否可以使用 jQuery 触发事件以在 n 之后设置 div 标签的文本。秒?
Thanks! George
谢谢!乔治
回答by Drew Wills
var doIt = function() {
$("div.my").text("My message");
}
setTimeout(doIt, 3000);
回答by Ed James
if you're using jQuery 1.4, you can always do:
如果您使用的是 jQuery 1.4,您可以随时执行以下操作:
$(function() {
$('#divId').delay(3000).text('New Text');
});
回答by John Himmelman
I've been using the following jQuery plugins below for this. Delay can be used with chained functions, notNow can't.
为此,我一直在使用以下 jQuery 插件。Delay 可以与链式函数一起使用,而 notNow 不能。
Delay
延迟
http://plugins.jquery.com/project/delay
http://plugins.jquery.com/project/delay
$('#animate-this').fadeIn().delay(500).fadeOut();
notNow
现在不要
http://plugins.jquery.com/project/notNow
http://plugins.jquery.com/project/notNow
$.notNow(2000, function() {
alert('woolsworth');
});