Example:
Days left: 08 days 02 things 02 minutes 02 seconds
HTML code:
<DivID= "Timer"Data-timer= "20160628140203"style= "font-size:20px">days Left:<spanID= "Timer_d">0</span>days<spanID= "Timer_h">0</span>when<spanID= "Timer_m">0</span>points<spanID= "timer_s">0</span>seconds</Div>
JS Code:
Timer (' timer ');//Calling Methods //time and seconds Countdown methodfunctionTimer (eleid) {varElement=document.getElementById (Eleid); if(Element) {EndTimer=element.getattribute (' Data-timer '); varEndtime=NewDate (parseint (Endtimer.substr (0,4), parseint (ENDTIMER.SUBSTR), 4,2 (parseint (ENDTIMER.SUBSTR), 10), parseint (Endtimer.substr (8,2), parseint (ENDTIMER.SUBSTR), 10,2 (parseint (ENDTIMER.SUBSTR), 10)); varEndtimemonth=endtime.getmonth ()-1; Endtime.setmonth (Endtimemonth); varTS = endTime-NewDate (); if(ts>0){ varDD = parseint (TS/1000/60/60/24, 10); varHH = parseint (ts/1000/60/60% 24, 10); varMM = parseint (ts/1000/60% 60, 10); varSS = parseint (ts/1000% 60, 10); DD= dd<10? ("0" + dd):d D;//daysHH = hh<10? ("0" + hh): HH;//whenMM = mm<10? ("0" + mm): mm;//pointsSS = ss<10? ("0" + ss): SS;//secondsdocument.getElementById ("Timer_d"). innerhtml=DD; document.getElementById ("Timer_h"). innerhtml=hh; document.getElementById ("Timer_m"). innerhtml=mm; document.getElementById ("timer_s"). innerhtml=SS; SetTimeout (function() {timer (Eleid);},1000); }Else{document.getElementById ("Timer_d"). innerhtml=0; document.getElementById ("Timer_h"). innerhtml=0; document.getElementById ("Timer_m"). innerhtml=0; document.getElementById ("timer_s"). innerhtml=0; } } }
Original address: http://blog.csdn.net/xw505501936/article/details/51554835
JS implementation of time and seconds countdown