您的位置:首页 > Web前端 > JavaScript

Javascript 实现的计时器

2015-06-02 11:42 549 查看
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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Javascript 计时器