Detailed explanation of the use of setTimeout() in JavaScript

黄舟
Release: 2017-12-04 10:24:43
Original
1917 people have browsed it

The setTimeout method in

JavaScriptis often used when the page is refreshed, delayed execution, etc. However, many JavaScript novices still don’t know much about the usage of setTimeout. Today I will introduce JavaScript to you. Detailed explanation of the use of setTimeout()!

Usage of setTimeout

Let us run a case together. First open Notepad, paste the following code into it, and run the effect!

    

haorooms博客示范网页

请等三秒!

Copy after login

The page will pop up a picture frame after staying for three seconds! This case uses the most basic syntax of setTimeout, and setTimeout will not be automatically repeated!

setTimeout can also execute functions and can be executed repeatedly! Let’s do another case together:

     
Copy after login

You can see that the number in the input text box increases every second! Therefore, setTimeout can also make time jumps in web pages!

Without a case, learning will not be fast. Let’s do an example together to calculate the time you stay on a certain page of haorooms:

     
你在haorooms博客中的停留时间是:
秒。
Copy after login

How about, through the above example, how about I believe you understand the usage of setTimeout()!

Summary:

Through the above explanation, I wonder if you understand setTimeout, and will you be very skilled in using setTimeout next time? Hope it helps with your work!

Related recommendations:

setTimeout instance

setTimeout() function in js

detailed explanation of usage examples of javascript function setTimeout with parameters

Let’s talk about the event loop model from setTimeout

The above is the detailed content of Detailed explanation of the use of setTimeout() in JavaScript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!