有没有办法在JavaScript中定期调用函数? [英] Is there any way to call a function periodically in JavaScript?
本文介绍了有没有办法在JavaScript中定期调用函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在JavaScript中定期调用函数?
Is there any way to call a function periodically in JavaScript?
推荐答案
你想要 setInterval( )
:
var intervalID = setInterval(function(){alert("Interval reached");}, 5000);
setInterval()也可以是要评估的代码字符串。
The first parameter to setInterval() can also be a string of code to be evaluated.
您可以清除周期性函数:
You can clear a periodic function with:
clearInterval(intervalID);
这篇关于有没有办法在JavaScript中定期调用函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文