Home  >  Article  >  Web Front-end  >  How to call setinterval() and clearInterval() JS functions_javascript skills

How to call setinterval() and clearInterval() JS functions_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:18:431566browse

The example in this article describes how to call the setinterval() and clearInterval() JS functions. Share it with everyone for your reference. The details are as follows:

Copy code The code is as follows:



Usage of setinterval() and clearInterval()




















The setInterval() method can call a function or calculate an expression according to the specified period (in milliseconds).
The setInterval() method will continue to call the function until clearInterval() is called or the window is closed. The ID value returned by setInterval() can be used as an argument to the clearInterval() method.
Grammar

Copy code The code is as follows:
setInterval(code,millisec[,"lang"])

参数 描述
code 必需。要调用的函数或要执行的代码串。
millisec 必须。周期性执行或调用 code 之间的时间间隔,以毫秒计。

setTimeout only runs once, which means that when the set time is up, the specified code will be triggered to run, and it will end after running.
setinterval runs in a loop, that is, the specified code is triggered every time the set time interval is reached. This is a real timer.

I hope this article will be helpful to everyone’s JavaScript programming design.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn