Javascript 实现的计时器
分享一个Javascript 实现的计时器,具有开始、暂停、继续、停止功能
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="timer"></div>
</body>
</html>
<script>
var tSeconds = 0;
var Timer = {
start: function () {
var self = this;
this.interval = setInterval(function () {
tSeconds += 1;
$('timer').html(Math.floor(tSeconds / 3600) + ":" + Math.floor(tSeconds / 60 % 60) + ":" + parseInt(tSeconds % 60));
}, 1000);
},
pause: function () {
clearInterval(this.interval);
delete this.interval;
},
resume: function () {
if (!this.interval)
this.start();
},
stop: function () {
clearInterval(this.interval);
$('#total-time-show').html("-");
tSeconds = 0;
}
};
Timer.start();
</script>