每30秒执行一次功能javascript [英] Run a function every 30 seconds javascript

查看:71
本文介绍了每30秒执行一次功能javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图每30秒运行一个函数,但是setInterval等待30秒,然后重复运行它.因此,如果还有其他方法可以解决此问题.(没有第三方插件)

I am trying to run a function every 30 seconds but setInterval waits 30 seconds then runs it repeatedly. So if there are any other methods of going about this. (Without 3rd party plugins)

任何帮助将不胜感激

推荐答案

基于"Schechter"的回答,但已修复为在首次加载页面时运行,然后每30秒运行一次.

Based on the answer from "Schechter" but fixed to run on the first page load and then runs every 30 secs.

function myFunction(){
    console.log('myFunction Called')
}

myFunction();

setInterval(function(){
    myFunction()
}, 30000)

这篇关于每30秒执行一次功能javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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