我需要更改以下代码,使函数createTimer接收两个参数(小时和分钟),输出格式必须为“小时 分钟 秒”,我无法解决这个问题。
function createTimer(options) {
var timer,
instance = this,
seconds = options.seconds,
updateStatus = options.onUpdateStatus || function () {},
counterEnd = options.onCounterEnd || function () {};
function decrementCounter() {
updateStatus(seconds);
if (seconds === 0) {
counterEnd();
instance.stop();
}
seconds--;
}
this.start = function () {
clearInterval(timer);
timer = 0;
seconds = options.seconds;
timer = setInterval(decrementCounter, 1000);
};
this.stop = function () {
clearInterval(timer);
};
}
function startTimer() {
var timer = new createTimer({
seconds: 10,
onUpdateStatus: function (seconds) {
document.getElementById("timer").innerHTML = seconds + " seconds";
},
onCounterEnd: function () {
document.getElementById("timer").innerHTML = "Time's up";
},
});
timer.start();
}
createTimer
函数接受小时和分钟而不是秒? - derpirscher