function pad(val) {
return val > 9 ? val : "0" + val;
}
setInterval(function() {
$("#seconds").html(pad(++sec % 25000));
}, 1);
我只是希望这些秒数停止在25,000并保持这种状态,除非页面明显刷新了...我可以在此代码中添加什么?
您可以仅添加一个if语句。
let sec = 0;
function pad(val) {
return val > 9 ? val : "0" + val;
}
setInterval(function() {
if (sec < 25000) {
$("#seconds").html(pad(++sec % 25000));
}
}, 1);
并且,如果您想清除间隔,使其不再一起运行,则>]
const countUp = setInterval(function() {
if (sec < 25000) {
$("#seconds").html(pad(++sec % 25000));
} else {
clearInterval(countUp);
}
}, 1);