题解 | #倒计时#
倒计时
http://www.nowcoder.com/practice/d86defce50ea45dd92c7a4fbde17d64b
function second(second) { let day = Math.floor(second/(60*60*24)); let hour = Math.floor(second%(60*60*24)/(60*60)); let min = Math.floor(second%(60*60)/60); let sec =second%60; return {day:day, hour:hour, min:min, second:sec} } function render(data) { let time = document.getElementsByTagName("span"); if(data.day==0){ time[0].classList.add('hide'); } data.day<10?(time[0].innerHTML=`0${data.day}天`):(time[0].innerHTML=`${data.day}天`); data.hour<10?time[1].innerHTML=`0${data.hour}:`:time[1].innerHTML=`${data.hour}:`; data.min<10?time[2].innerHTML=`0${data.min}:`:time[2].innerHTML=`${data.min}:`; data.second<10?time[3].innerHTML=`0${data.second}`:time[3].innerHTML=`${data.second}`; }