1. Introduction The 2. The difference between setInterval and setTimeout When talking about 3. setTimeout Definition and Usage: Syntax: Parameters: code (required): The
setInterval: Syntax: Parameters: Return value: A value that can be passed to the difference: As can be seen above, the main differences between Personally, I prefer to use setTimeout more! 4. Usage of setTimeoutLet's run a case together. First, open Notepad, paste the following code in, and run it to see the effect! <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <h1> <font color=blue> haorooms blog demonstration page</font> </h1> <p>Please wait three seconds!</p> <script> setTimeout("alert('Sorry, haorooms blog has kept you waiting for a long time')", 3000 ) </script> </body> </html> The page will pop up a picture frame after staying for three seconds! This case applies the most basic syntax of Let’s do another case together: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script> var x = 0 function countSecond() { x = x+1 document.haorooms.haoroomsinput.value=x setTimeout("countSecond()", 1000) } </script> </head> <html> <body> <form name="haorooms"> <input type="text" name="haoroomsinput"value="0" size=4 > </form> <script> countSecond() </script> </body> </html> We can see that the number in the Without examples, learning will not be fast. Let's do another example to calculate your stay time on a certain page of <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script> x=0 y=-1 function countMin() { y=y+1 document.displayMin.displayBox.value=y setTimeout("countMin()",60000) } function countSec() { x = x + 1 z = x % 60 document.displaySec.displayBox.value=z setTimeout("countSec()", 1000) } </script> </head> <body> <table> <tr valign=top> <td> Your stay time in haorooms blog is: </td> <td> <form name=displayMin> <input type=text name=displayBox value=0 size=4 > </form> </td> <td> points</td> <td> <form name=displaySec> </td> <td> <input type=text name=displayBox value=0 size=4 > </form> </td> <td> seconds. </td> </tr> </table> <script> countMin() countSec() </script> </body> </html> How about it? Through the above examples, I believe you have understood the usage of 5. clearTimeout() Let's take a look at clearTimout() has the following syntax: To use In the following example, two as follows: By using the Please see the example of clearTimeout() below; <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script> x = 0 y = 0 function count1() { x = x + 1 document.display1.box1.value = x meter1=setTimeout("count1()", 1000) } function count2() { y = y + 1 document.display2.box2.value = y meter2 = setTimeout("count2()", 1000) } </script> </head> <body> <p> </br> <form name="display1"> <input type="text" name="box1" value="0" size=4 > <input type=button value="Stop timing" onClick="clearTimeout(meter1) " > <input type=button value="Continue timing" onClick="count1()" > </form> <p> <form name="display2"> <input type="text" name="box2" value="0" size=4 > <input type=button value="Stop timing" onClick="clearTimeout(meter2) " > <input type=button value="Continue timing" onClick="count2()" > </form> <script> count1() count2() </script> </body> </html> 6. ConclusionThis is the end of this article about the usage summary of javascript's setTimeout(). For more information about the usage of javascript's setTimeout(), please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Implementation of MySQL GRANT user authorization
>>: Why can't my tomcat start?
Since Zabbix version 3.0, it has supported encryp...
Optimize queries Use the Explain statement to ana...
In requireJS, there is a property called baseURL....
As a required course for front-end developers, CS...
Table of contents 1. Project Prospects 2. Knowled...
1. Prerequisites 1. The project has been deployed...
Table of contents Written in front Login Overview...
Table of contents Overview How to share data betw...
1. Unzip the zip package to the installation dire...
When modifying Magento frequently, you may encount...
introduction Currently, k8s is very popular, and ...
Table of contents 1. beforeunload event 2. Unload...
1. Summary: In general, they can be divided into ...
tcpdump is a flexible and powerful packet capture...
I recently made a file system and found that ther...