Get the App
SLTechnology News&Howtos  ›  Development  › 

How to set up a few-second loop in jquery

Shulou Source: shulou.com Published: 2022-06-02 03:28:06 09月17日 Update

Today Xiaobian to share with you how to set up a few seconds cycle of jquery related knowledge points, detailed content, clear logic, I believe most people still know too much about this knowledge, so share this article for everyone to refer to, I hope you read this article after some gains, let's learn about it together.

In jquery, you can set a few seconds to loop the specified code using the setInterval() method, which calls a function or evaluates an expression at a specified period in milliseconds until clearInterval() is called or the window is closed, with the syntax "setInterval(call function, time)."

Operating environment for this tutorial: Windows 10 system, jquery version 3.2.1, Dell G3 computer.

How does jquery set up a few seconds cycle

The setInterval() method calls a function or evaluates an expression for a specified period (in milliseconds).

The setInterval() method keeps calling 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 is required. The function to call or the string of code to execute.

Millisec must. The time interval between periodic execution or invocation of code, in milliseconds.

return value

A value that can be passed to Window.clearInterval() to cancel periodic execution of code.

examples

var int=self.setInterval("clock()",50)function clock() { var t=new Date() document.getElementById("clock").value=t }

Tags: Functions methods loops cycles knowledge articles code content parameters periodicity time expressions syntax differences great between most examples that is tutorials Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info vpn MySQL Apple NVidia