Home > front end >  Js setInterval second parameter can be used in variable?
Js setInterval second parameter can be used in variable?

Time:10-02

My code setInterval the second parameter used variables, can be found, but whether a variable is any value, by 1 second cycle running?
Anyone know what's going on?

CodePudding user response:

Var time=20003,
N=0;
SetInterval (function () {
The console. The log (n++);
}, time);

You refer to this example

CodePudding user response:

SetInterval second parameter variables as long as is really value, is not a problem, it is best to be sent out to look at the code has a problem where written

CodePudding user response:

I use clearInterval can remove at the front of the timer, but pass any time parameters, according to a second cycle, even in a shorter cycle run,

CodePudding user response:

Not set the time interval is invalid, but before the start of the timer is not properly closed, after repeatedly to start the timer to your feeling is the actual timer interval shorter than setting the time interval,

CodePudding user response:

The second parameter is the unit of milliseconds, positive integers less than 1000 will run in a seconds

CodePudding user response:

reference under the pine reply: 3/f
I use clearInterval can remove at the front of the timer, but pass any time parameters, according to a second cycle, running, even shorter cycle

Send the code, we can determine what the problem is,

CodePudding user response:

No problem:
  • Related