每 30 秒运行一个函数 javascript [英] Run a function every 30 seconds javascript

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

问题描述

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

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天全站免登陆