如何将函数调用延迟5秒? [英] How do I delay a function call for 5 seconds?

查看:420
本文介绍了如何将函数调用延迟5秒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望 widget.Rotator.rotate()在调用之间延迟5秒...我如何在jQuery中执行此操作...它似乎是jQuery的 delay()对此不起作用...

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...

推荐答案

你可以使用普通的javascript,这将在5秒后调用your_func一次:

You can use plain javascript, this will call your_func once, after 5 seconds:

setTimeout(function() { your_func(); }, 5000);

如果您的函数没有参数且没有明确的接收器,您可以直接调用 setTimeout (func,5000)

If your function has no parameters and no explicit receiver you can call directly setTimeout(func, 5000)

还有一个我曾经使用过的插件。它有 oneTime everyTime 方法。

There is also a plugin I've used once. It has oneTime and everyTime methods.

  • jQuery timers plugin

这篇关于如何将函数调用延迟5秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆