您的位置:首页 > Web前端 > JavaScript

JS中的两个经常用的函数setTimeout和clearTimeout例子

2010-07-08 23:39 459 查看
例子:

<html>
<head>
<script type="text/javascript">
var c=0;
var t;
function timedCount() { document.getElementById('txt').value=c; c=c+1; t=setTimeout("timedCount()",1000); }
function stopCount() { clearTimeout(t); }</script>
</head>
<body>
<form>
<input type="button" value="Start count!" onClick="timedCount()">
<input type="text" id="txt">
<input type="button" value="Stop count!" onClick="stopCount()">
</form>
</body>
</html>

P.S这两个函数可以在DHTML 手册.chm中查看

此外setTimeout和setInterval区别可以见下面链接:

http://book.csdn.net/bookfiles/344/10034413534.shtml
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: