您需要使用setInterval以进行实际计数,如果这是您想要实现的目标: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>