我有一个代码用于递减计数等于6
的计时器,但是我想像这样hrs:min:sec
递减格式为00:00:10
的count的值
function countdown() {
// starts countdown
if (count == 0) {
// time is up
} else {
count--;
t = setTimeout("countdown()", 1000);
}
};
,计数为00:00:10,持续10秒钟。如何减少计时器?有人可以帮我吗?
答案 0 :(得分:0)
类似的事情将满足您的需求:
function showCountdown(countSeconds)
{
var countStatus = new Date(1000 * countSeconds).toISOString().substr(11, 8);
document.getElementById('output').innerHTML = "Count: " + countStatus;
}
var count = 10;
function countdown() {
// starts countdown
if (count === 0) {
return;
}
count--;
setTimeout(countdown, 1000);
showCountdown(count);
};
countdown();
<div id="output">
</div>
我已经将JSFiddle更新为HH:mm:ss格式 JSFiddle:https://jsfiddle.net/8uhq0vej/7/