JS 页面计时器示例代码

计时器效果想必大家都见到过吧,其实使用js可以很轻松的实现,下面有个不错的示例,感兴趣的朋友可以参考下

复制代码 代码如下:


<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<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="开始计时!">
<input type="text">
<input type="button" value="停止计时!">
</form>
<p>请点击上面的“开始计时”按钮来启动计时器。输入框会一直进行计时,从 0 开始。点击“停止计时”按钮可以终止计时。</p>
<p>timedCount(),1000ms自己调自己。</p>
</body>
</html>

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wdzzgf.html