Home  >  Article  >  Web Front-end  >  js中setTimeout()与clearTimeout()用法实例浅析_javascript技巧

js中setTimeout()与clearTimeout()用法实例浅析_javascript技巧

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

本文实例分析了js中setTimeout()与clearTimeout()用法。分享给大家供大家参考。具体分析如下:

setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式.

clearTimeout() 方法可取消由 setTimeout() 方法设置的 timeout.

<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>

希望本文所述对大家的javascript程序设计有所帮助。

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