猿问

如何用javascript实现倒计时?

如何用javascript实现倒计时


慕侠2389804
浏览 576回答 2
2回答

猛跑小猪

<html><head><meta charset="utf-8"><script>var timeCounter = (function() {var int;var total = 3600;return function(elemID) {obj = document.getElementById(elemID);var s = (total%60) < 10 ? ('0' + total%60) : total%60;var h = total/3600 < 10 ? ('0' + parseInt(total/3600)) : parseInt(total/3600);var m = (total-h*3600)/60 < 10 ? ('0' + parseInt((total-h*3600)/60)) : parseInt((total-h*3600)/60);obj.innerHTML = h + ' : ' + m + ' : ' + s;total--;int = setTimeout("timeCounter('" + elemID + "')", 1000);if(total < 0) clearTimeout(int);}})()</script></head><body onLoad="timeCounter('timeCounter')"><p id="timeCounter">01 : 00 : 00</p></body></html>
随时随地看视频慕课网APP
我要回答