JavaScript DHTML/Window Browser/setTimeout
Содержание
Load image with timer
<source lang="html4strict">
<html> <head> <title>Timers</title> <script type="text/javascript"> var ct = 0; var imgs = new Array("a.gif","b.gif","c.gif"); setTimeout("progress()",3000); function progress() {
if (ct < 3) { document.images[0].src=imgs[ct]; ct++; setTimeout("progress()",3000); }
} </script> </head> <body> <img src="d.gif" /> </body> </html>
</source>
meta http-equiv="refresh" content="30" and timer
<source lang="html4strict">
<html> <head> <title>A Simple Page</title> <meta http-equiv="refresh" content="30"> <script language="JavaScript"> var x=30; function startClock(){
x = x - 1; document.form1.clock.value = x; timerID=setTimeout("startClock()", 1000);
} </script> </head> <body onload="startClock()"> <form name="form1"> <input type="text" name="clock"> </form> </body> </html>
</source>
Start a timer and cancel a timer
<source lang="html4strict">
<HTML> <HEAD> <SCRIPT> var myTimer;
function fireIt () {
var now = new Date(); var displayStr = now + "\r\n"; window.document.theForm.myOutput.value = displayStr;
} function startIt () {
myTimer = setInterval("fireIt()", 1000);
} function stopIt() {
clearInterval(myTimer);
} </SCRIPT> </HEAD> <BODY>
</BODY> </HTML>
</source>
Windows timer
<source lang="html4strict">
<html> <head> <title>timer</title> <script type="text/javascript"> function sendAlert() {
document.write("Hello");
} function startTimer() {
var timerID = window.setTimeout(sendAlert,8000);
} </script> </head> <body onload="startTimer();">
Hello
</body> </html>
</source>