Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
491 views
in Technique[技术] by (71.8m points)

javascript - 如何将函数调用延迟5秒钟? [重复](How do I delay a function call for 5 seconds? [duplicate])

This question already has an answer here:(这个问题已经在这里有了答案:)

Sleep in JavaScript - delay between actions 10 answers(睡在JavaScript中-动作之间的延迟 10个答案)

I want widget.Rotator.rotate() to be delayed 5 seconds between calls... how do I do this in jQuery... it seems like jQuery's delay() wouldn't work for this...(我希望在widget.Rotator.rotate()调用之间将widget.Rotator.rotate()延迟5秒...我该如何在jQuery中执行此操作...看来jQuery的delay()对此不起作用...)

  ask by Webnet translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use plain javascript, this will call your_func once, after 5 seconds:(您可以使用普通的javascript,这将在5秒后调用一次your_func:)

setTimeout(function() { your_func(); }, 5000); If your function has no parameters and no explicit receiver you can call directly setTimeout(func, 5000)(如果您的函数没有参数且没有显式接收器,则可以直接调用setTimeout(func, 5000)) There is also a plugin I've used once.(我曾经用过一个插件。) It has oneTime and everyTime methods.(它具有oneTimeeveryTime方法。) jQuery timers plugin(jQuery计时器插件)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...