我有这个功能,只要我点击一个按钮,就会以00:00:00的格式启动计时器.但我不知道如何做功能恢复和暂停.我发现了一些我认为可能有用的片段,但我无法完成这些工作.我是新手在js中使用对象.
function clock() {
var pauseObj = new Object();
var totalSeconds = 0;
var delay = setInterval(setTime, 1000);
function setTime() {
var ctr;
$(".icon-play").each(function () {
if ($(this).parent().hasClass('hide')) ctr = ($(this).attr('id')).split('_');
});
++totalSeconds;
$("#hour_" + ctr[1]).text(pad(Math.floor(totalSeconds / 3600)));
$("#min_" + ctr[1]).text(pad(Math.floor((totalSeconds / 60) % 60)));
$("#sec_" + ctr[1]).text(pad(parseInt(totalSeconds % 60)));
}
}
Run Code Online (Sandbox Code Playgroud)
pad()只是添加前导零