0
所以我有一个是从一个onload
事件调用的函数:setTimeout连续运行它的函数?
var called = 0;
function getAll()
{
var msg = "hello everyone";
alert("hi");
setTimeout(startTimerRepeat, 5000, msg);
}
function startTimerRepeat(content)
{
document.getElementById('howmanyLbl').innerText = "Called " + called + " times, " + msg;
}
我预计startTimerRepeat()
功能每5秒被调用,它的作用。然而,似乎getAll()
函数也每5秒执行一次,因为每5秒连续出现一次带有“hi”的警报。
有没有人明白我在做什么错在这里?
'我希望被称为startTimerRepeat()函数每5秒钟你在哪里做?谁每5秒钟调用一次'startTimerRepeat'? – gurvinder372
在title中回答你的问题:nope,'setInterval'不断地做。 –
您需要为您的问题添加更多代码,以便我们弄清楚。具体来说,你从哪里调用getAll()。另外,'setTimeout()'只会在延迟后执行一次函数。 'setInterval()'是你在这里寻找的东西。 – Matt