When using setinterval, it is found that it will be executed after a delay of one second when the page is just opened. Because the setinterval timer executes its own one second first, and then operates on the content inside, it will not be displayed immediately. For example: first create a div box, then write the script code var div = document.querySelector('div'); var num = 10; setInterval(function(){ if(num==1){ div.innerHTML = null; return fn1; }else{ num--; div.innerHTML = 'Remaining' + num + 'seconds'; } },1000); The effect is as shown below: It will execute for that second first, wait for one second and then execute the content displayed in it Solution: Direct call var div = document.querySelector('div'); var num = 11; function fn1(){ if(num==1){ div.innerHTML = null; return fn1; }else{ num--; div.innerHTML = 'Remaining' + num + 'seconds'; } } setInterval(fn1,1000); fn1(); This is the end of this article about the solution to the one-second delay of JavaScript setinterval. For more information about the solution to the one-second delay of JavaScript setinterval, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Basic statements of MySQL data definition language DDL
>>: Tomcat maxPostSize setting implementation process analysis
This article shares with you how to install the M...
1. The ENV instruction in the Dockerfile is used ...
Vmware Installation Installing Packages Download ...
I feel that the explanation of this.$set on the I...
Table of contents Purpose npm init and package.js...
Copy code The code is as follows: <span style=...
Data Type: The basic rules that define what data ...
Table of contents 1. Memory model and runtime dat...
Pure CSS3 makes a butterfly flapping its wings, s...
The notepad program is implemented using the thre...
1. v-on event monitoring To listen to DOM events,...
Docker version 1.13.1 Problem Process A MySQL con...
In combination with the scenario in this article,...
A set of projects for training react+ts Although ...
Table of contents 1. What is a calculated propert...