gpt4 book ai didi

javascript - 清除设定间隔

转载 作者:行者123 更新时间:2023-12-02 15:21:27 25 4
gpt4 key购买 nike

 setInterval(function hello() {
console.log('hello world');
return hello;
}(), 6000);

如何清除间隔,我尝试添加 var 间隔

var i =0;
var interval = setInterval(function hello() {
console.log('world');
if(++i == 3) clearInterval(interval);
return hello;
}(), 5000);

但是没有成功。感谢您的帮助。

最佳答案

clearInterval() 当然有效。以下代码行有错误:

    }(), 5000);
//^^ remove () as this is not IIFE

关于javascript - 清除设定间隔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34012237/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com