Pages

Friday, 28 February 2014

How to setTimeout Function Example JavaScript c#

How to setTimeout Function Example JavaScript c#

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 on webpage
JavaScript Display current time second by second:


No comments:

Post a Comment