简易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="开始计时!" onClick="timedCount()">
<input type="text" id="txt">
<input type="button" value="停止计时!" onClick="stopCount()">
</form>
<p>请点击上面的“开始计时”按钮来启动计时器。输入框会一直进行计时,从 0 开始。点击“停止计时”按钮可以终止计时。</p>
<p>timedCount(),1000ms可以调成自己需要的计时间隔,这里1000MS正好是1秒钟,也就是1秒钟跳动一次加1。</p>
</body>
</html>
顶(2)
踩(0)
下一篇:HTML+原生JS的倒计时小工具
- 最新评论
