I have something like this:
function myFunction()
{
var testVar;
if(txt == "Maybe")
{
txt == "No";
testVar = setInterval(function(){ zrobTo() }, 1000);
}
else if(txt == "No")
{
txt == "Maybe";
clearInterval(testVar);
}
}
When clearInterval
isn't in if then code is working, but I wanna have this in if. Is it possible?
The reason is that the setInterval is never leaving the function. Since the variable is local, it is deleted when the function ends. There is no way around this that I have found. D=
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.