How to setTimeout Function Example JavaScript c#
Method 1:
Method 2:
Sample Code:
Live Demo:
Method 1:
setTimeout(yourfunction(), timeinterval); function yourfunction() { // your code here } |
Method 2:
setTimeout(function(){// your code here }, timeinterval); |
Sample Code:
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>JavaScript display current time on webpage</title> <script type="text/javascript"> function ShowCurrentTime() { var dt = new Date(); document.getElementById("lblTime").innerHTML = dt.toLocaleTimeString(); setTimeout("ShowCurrentTime()", 1000); // Here 1000(milliseconds) means one 1 Sec } </script> </head> <body onload="ShowCurrentTime()"> <div> JavaScript Display current time second by second: <label id="lblTime" style=" font-weight:bold"></label> </div> </body> </html> |
Live Demo:
JavaScript Display current time second by second:
|
No comments:
Post a Comment