gpt4 book ai didi

javascript - clearInterval 不会停止 setInterval

转载 作者:行者123 更新时间:2023-11-29 20:02:18 25 4
gpt4 key购买 nike

我有 1 个按钮可以打开和关闭:按钮打开 -> onrepeat = true按钮关闭 -> onrepeat = false

如果 onrepeat 为真,则 setinterval 开始,它就很好。如果 onrepeat 为假,我希望它清除间隔。

我的清除间隔不会停止间隔,它会继续:

 function checkRepeat() {

var int = setInterval(repeat, 6000);

if (onrepeat === false) {
$("#repeat_toggle").attr("class", "repeat_button");

repeat();
int;

onrepeat = true;

}

else {

clearInterval(int);
$("#repeat_toggle").attr("class", "repeat_off_button");
onrepeat = false;

}


}

知道哪里出了问题吗?

最佳答案

int 的范围是函数。每次调用 checkRepeat

时它都会重置

您需要将其限定在函数之上的级别。

关于javascript - clearInterval 不会停止 setInterval,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13729395/

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