js秒表计时工具
单位 秒
<!DOCTYPE html>
<html>
<body>
<div align="center">
<h1>计时器</h1>
<h2 id="timer">0</h2>
<button onclick="startTimer()">开始</button>
<button onclick="stopTimer()">停止</button>
<button onclick="restTimer()">刷新</button>
</div>
</style>
<script>
var sec = 0;
var timer;
function startTimer() {
timer = setInterval(function () {
sec++;
document.getElementById('timer').innerHTML = sec;
}, 1000);
}
function stopTimer() {
clearInterval(timer);
}
function restTimer() {
sec = 0;
document.getElementById('timer').innerHTML = sec;
}
</script>
</body>
</html>
效果图