本文介绍了JavaScript-SetInterval无法正常运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到了这段脚本(在本地运行):
I got this piece of script (runned locally):
<script>
last = 0;
function uploadnew(){
var randomnumber=Math.floor(Math.random()*6);
if(randomnumber != last){
document.forms['f'+randomnumber].submit();
} else { uploadnew(); }
}
setInterval (uploadnew(), 1000*60*5);
</script>
但是似乎setInterval不起作用/发送表单函数不起作用...
But it seems that setInterval is not working / send form function doesn't work...
任何帮助将不胜感激!
谢谢!
推荐答案
您需要致电 setInterval()
在函数上不带括号,例如:
You need to call setInterval()
without parenthesis on your function, like this:
setInterval(uploadnew, 1000*60*5);
使用括号立即将其称为 并分配结果( undefined
)以一定的间隔运行,而不是使用括号来传递函数本身,而不是函数的结果.
Using parenthesis you're calling it immediately and assigning the result (undefined
) to be run on an interval, instead don't use parenthesis to pass the function itself, not the result of the function.
这篇关于JavaScript-SetInterval无法正常运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!