<div> from page close and <span id= "Limit" >5</span> sec </div>
| code is as follows |
copy code |
<script type=" Text/javascript "> <!-- Function Showlimit () { for (Var i=5;i>=0;i--) { settimeout ("Setlimit" +i+ ")", i*1000); } } function Setlimit (i) { var n =-(i-5); var obj = document.getElementById ("Limit"); if (obj) { obj.innerhtml = n; } } Window.onload = function () { showlimit (); } //--> </script> |
Apply to window closure prompts, page closure prompts, and so on, note that JavaScript negative negative positive this algorithm.
See example one delay loading code
| The code is as follows |
Copy Code |
<script type= "Text/javascript" > function Timedtext () { var t1=settimeout ("document.getElementById" (' txt '). value= ' 2 seconds! ' ", 2000) var t2=settimeout ("document.getElementById" (' txt '). value= ' 4 seconds! ' ", 4000) var t3=settimeout ("document.getElementById" (' txt '). value= ' 6 seconds! ' ", 6000) } </script> |
This is a section of JS code is 2,4,6 seconds to perform once.
Inside the form is as follows.
| The code is as follows |
Copy Code |
<input type= "button" value= "Displays the timed text!" "Onclick=" Timedtext () > <input type= "text" id= "TXT" > |
So we can just type in a character and start to see the 2,4,6 show Oh.
For more details please see: http://www.111cn.net/wy/99/e80915fb120d9b233c8471240a7390aa.htm
settimeout implementation of automatic change shows the effect of random numbers:
| The code is as follows |
Copy Code |
<script> Window.onload=sett; function Sett () { Document.body.innerhtml=math.random (); settimeout ("Sett ()", 500); } </script> <body> </body> |
Related functions:
The settimeout () method is used to call a function or evaluate an expression after a specified number of milliseconds.
SetTimeout () executes only one code at a time. If you want to call more than once, use SetInterval () or let code itself call SetTimeout () again.
Automatic changes with setinterval to display the effect of random numbers:
| code is as follows |
copy code |
| <script> Function sett () { Document.body.innerhtml=math.random (); } SetInterval ("Sett ();", 500); </script> </script> <body> </body> /td> |