Syntax
setTimeout("MethodName()","DelayTime")
Example Clock
This example used to create interactive clock on your webpage by using setTimeout() and show output on <div id="divOutput">. You can move this tag everywhere to show your clock on your webpage.
<script language="JavaScript">
function callTime() {
var d = new Date();
var result = d.getDate()+"/";
result += (d.getMonth()+1)+"/";
result += d.getYear() + " ";
result += d.getHours() + ":"
result += d.getMinutes() + ":";
result += d.getSeconds();
document.getElementById("divOutput").innerHTML = result;
setTimeout("callTime()", 1000);
}
</script>
<body onload="callTime();">
<div id="divOutput"> </div>
</body>
result += (d.getMonth()+1)+"/";
result += d.getYear() + " ";
result += d.getHours() + ":"
result += d.getMinutes() + ":";
result += d.getSeconds();
document.getElementById("divOutput").innerHTML = result;
setTimeout("callTime()", 1000);
}
</script>
<body onload="callTime();">
<div id="divOutput"> </div>
</body>
##############################
Reference : http://www.w3schools.com/
No comments:
Post a Comment