我正在尝试获取它,以便用户在提示中输入的每 n 秒都会弹出确认窗口,但无论输入如何,确认窗口都会立即弹出。我做错了什么?
这是我的按钮的样子:
<button onclick="timer_prompt()">FUN</button>
<小时/>
我的简单功能:
function timer_prompt()
{
var seconds = prompt("Enter Time Interval In Seconds Please");
seconds = seconds*1000;
if(seconds>0)
{
setInterval(confirm_timer(), seconds);
}
else
{
alert("You entered invalid content");
}
}
function confirm_timer()
{
confirm("YOU HAVE SET A TIMER!!!");
}
最佳答案
您正在调用,而不是分配
setInterval(confirm_timer(), seconds);
需要
setInterval(confirm_timer, seconds);
关于javascript - setInterval 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26349281/