Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use setTimeout and setInterval of JavaScript

2025-01-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to use setTimeout and setInterval of JavaScript". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use setTimeout and setInterval of JavaScript".

i. General description

First of all, the setTimeout () and setInterval () functions are two very important "time functions" in JavaScript. Therefore, in the process of learning JavaScript, we must have an in-depth study of these two functions, and their two functions are often used!

Among them, if the two functions are summarized in one sentence respectively, it should look like this:

SetTimeout (): this function can delay the execution of events according to the set time value.

SetInterval (): this function can periodically execute the time in accordance with the set time value as an interval.

Of course, it's just a brief description, and we'll explain it to you in the following part.

II. SetTimeout () function

The first is our setTimeout () function. What is its format?

SetTimeout (function,times)

Yes, it is such a simple format, where we need two parameters, a function and an int value, which represents the body of the function to be executed after a delay for a period of time. For example, let's look at this simple piece of code:

SetTimeout (function () {alert ("hello,setTimeout ()");}, 1000)

After running, it will pop up a pop-up box after a delay of 1 second, in which 1000 of the units are milliseconds!

So far, people think it's very easy, right? OK, I'll give you a piece of code, and you can guess what it will output:

For (var I = 1; I

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 221

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report