0

I want to know if there is a way to restart/clear the setInterval(); function in Javascript? My problem is, when you go here:: http://jsfiddle.net/GqrRx/2/ (sorry it doesn't want to work here)... but if you go there and input a date, it works fine. But if you enter in another date, the seconds, minutes, and hours glitch up, and flicker. I think I need to find a way to restart the interval or stop it.

I tried putting this at the top of my function, but it didn't seem to do anything.

clearInterval(runSeconds);
clearInterval(runMinutes);
clearInterval(runHours);

I also tried this:

var secInt = setInterval(runSeconds, 1000);
var minInt = setInterval(runMinutes, 60000);
var hInt = setInterval(runHours, 3600000);
clearInterval(secInt);
clearInterval(minInt);
clearInterval(hInt);
4

1 に答える 1

1

の結果をsetInterval変数に設定し、その変数を に渡しますclearInterval

このようなもの:

var interval = setInterval(someFunc, 100);
clearInterval(interval);

詳細については、 https://developer.mozilla.org/en-US/docs/Web/API/window.setInterval?redirectlocale=en-US&redirectslug=DOM%2Fwindow.setInterval#Exampleを参照してください。

于 2013-07-27T18:57:25.727 に答える