Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
379 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 Reply

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计时器插件)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...