JavaScript DHTML/Window Browser/setTimeout

Материал из Web эксперт
Перейти к: навигация, поиск

Load image with timer

  
<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>



meta http-equiv="refresh" content="30" and timer

  
<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>



Start a timer and cancel a timer

  
<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>
<TABLE>
<FORM name="theForm">
     <input type=button value="Start!" onClick="startIt ();">
     <input type=button value="Stop!" onClick="stopIt();">
     <textarea name="myOutput" cols = 60 rows=20></textarea>
</FORM>
</TABLE>
</BODY>
</HTML>



Windows timer

 
<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();">
<p>Hello</p>
</body>
</html>