Home  >  Article  >  Web Front-end  >  A brief analysis of usage examples of setTimeout() and clearTimeout() in js_javascript skills

A brief analysis of usage examples of setTimeout() and clearTimeout() in js_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:59:361264browse

This article analyzes the usage of setTimeout() and clearTimeout() in js with examples. Share it with everyone for your reference. The specific analysis is as follows:

The setTimeout() method is used to call a function or calculate an expression after a specified number of milliseconds.

clearTimeout() method can cancel the timeout set by setTimeout() method.

<input type = text id = aaa >
<input type = button value = stop id = bb onclick = bb()>
<script>
<!--
var iTime
function aa()
{
 aaa.value += "!";
 iTime=setTimeout("aa()",600);
}
function bb()
{
 if (iTime !="")
 clearTimeout(iTime);
}
aa()
-->
</script>

I hope this article will be helpful to everyone’s JavaScript programming design.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn