(function(global) { var container = document.getElementById('clock-block'), getTime, revise, showTime, second; // 显示时间,刷新频率是1s showTime = function showTime() { var dateObj = new Date(), currentSecond = dateObj.getSeconds(), arr= []; if (second !== currentSecond) { arr.push(dateObj.getHours()); arr.push(dateObj.getMinutes()); arr.push(currentSecond); container.innerHTML = arr.join(':'); second !== currentSecond; } setTimeout(showTime, 100); }; showTime(); })(window);
<div id="clock-block"></div>