In jquery, you can use the setInterval() method to set the specified code for a few seconds loop. This method can call functions or calculate expressions according to the specified period in milliseconds until clearInterval() is called or the window is closed, the syntax is "setInterval(call function, time)".
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
How to set a few seconds loop in jquery
The setInterval() method can call a function or calculate an expression according to the specified period (in milliseconds) Mode.
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.
Syntax
setInterval(code,millisec[,"lang"])
Parameter Description
code Required. A function to be called or a string of code to be executed.
millisec Must. The time interval, in milliseconds, between periodic executions or calls to code.
Return value
A value that can be passed to Window.clearInterval() to cancel the periodic execution of code.
Example
<html> <body> <input type="text" id="clock" size="35" /> <script language=javascript> var int=self.setInterval("clock()",50) function clock() { var t=new Date() document.getElementById("clock").value=t } </script> </form> <button onclick="int=window.clearInterval(int)"> Stop interval</button> </body> </html>
Output result:
Related video tutorial recommendation: jQuery video tutorial
The above is the detailed content of How to set a few seconds loop in jquery. For more information, please follow other related articles on the PHP Chinese website!