Sunday, 3 March 2013

JAVA SCRIPT: Timing events

Hello friends

In this post am explain briefly in javascript Timing events and how to use in javascript?

Lets come !

Basic question for Timing Events

What is Time event?

       If you set of or block of code executed at specified time interval that is called time event.

Javascript use therae four methods use in time events
  1. setInterval
  2. clearInterval
  3. setTimeout
  4. clearTimeout
1.setInterval( )
  •  This method will wait and execute set of code at specified time interval.
  • This method will continue to execute at specified time interval

Syntax: 

setInterval("js function",timeinterval);

 Example:

setInterval("show()",2000);

<script>
setInterval(ff(),2000);

function ff()
{
alert("hello");
}
</script>


Note: The time interval denote no of milli seconds

2.clearInterval( )
  • This method stop the execution of setInterval() method
Syntax: 

clearInterval(setInterval method variable);

Example: 

clearInterval(stp); 

3.setTimeout
  • This method will wait and execute set of code at specified time interval.
  • This method will not continue to execute at specified time interval

Syntax: 

setTimeout("js function",timeinterval);

 Example:

 setTimeout("show()",2000);

<script>

setTimeout(aa(),2000);
function aa()
{
alert("hello all");
}

</script>

Note: The time interval denote no of milli seconds

4.clearTimeout
  • This method stop the execution of setTimeout() method variable

Syntax: 

clearTimeout(clearTimeoutmethod variable);

Example: 

clearTimeout(stp); 

Example for all:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">

function show()
{
var t=setTimeout(fun(),5000);
}

function show1()
{
var t=setTimeout(fun1(),5000);
}

function fun()
{
alert("Welcome Guyz");
}
function fun1()
{
alert("Welcome Guyz!!!!");
}
</script>
</head>

<body onload="show()">
<form>
<input type="button" value="Display SetTimeout alertbox!"
onClick="show()">
<input type="button" value="Display setInterval alertbox!"
onClick="show1()">
</form>
</body>
</html>

Am post more example later sesction. i hope useful to you

Thanks



No comments:

Post a Comment

What is AI- Artificial Intelligence - தமிழில்

Artificial Intelligence : Artificial intelligence leverages computers and machines to mimic the problem-solving and decision-making capabili...