html小小计时器
效果
代码
<!DOCTYPE html>
<html>
<head>
<title>简易计时器</title>
<script type="text/javascript"> var init; var time = 0; function start1(){ init = setInterval(timer,1000); } function timer(){ time =time+1; document.getElementById("timetext").value = time; } function stop1(){ clearInterval(init); } function reset1(){ time = 0; document.getElementById("timetext").value = time; } </script>
</head>
<body>
<input type="text" id="timetext" value="0" > 秒 <br>
<input type="button" value="开始" id="submit" onclick="start1()">
<input type="button" value="停止" id="stop" onclick="stop1()">
<input type="reset" name="reset" id="reset" onclick="reset1()">
</body>
</html>
笔记
setInterval的使用,每隔一定时间调用函数