1 回答

TA貢獻(xiàn)1744條經(jīng)驗(yàn) 獲得超4個(gè)贊
您需要使用setInterval以進(jìn)行實(shí)際計(jì)數(shù),如果這是您想要實(shí)現(xiàn)的目標(biāo):
function countUp() {
var i = 0; // a counter which is displayed every 100ms
// create interval which fires the callback every 100ms.
// `interval` holds the interval ID, which is later used to clear the
// interval (stop calling the callback)
var interval = setInterval(function() {
text.innerHTML = i++; // write `i` and increment
// if `i` is grater than 100 then clear the interval (stop calling the callback)
if (i > 100) clearInterval(interval);
}, 100);
}
countUp();
<div id="text"></div>
添加回答
舉報(bào)