js倒计时

来源:互联网 发布:eazz拉杆箱怎么样 知乎 编辑:程序博客网 时间:2024/06/06 17:25
第一种<html><head><script type="text/javascript">var c=100000000 var tfunction timedCount(){document.getElementById('but').disabled=truec=c-1000if(c<0){document.getElementById('txt').value="game over!"return;}showTime(c)t=setTimeout("timedCount()",1000)}function stopCount(){document.getElementById('but').disabled=falsesetTimeout(c,0);clearTimeout(t);}function resetCount(){stopCount();c=100000000showTime(c)}function showTime(nMS){    var nD = Math.floor(nMS/(1000 * 60 * 60 * 24));      var nH = Math.floor(nMS/(1000*60*60)) % 24;      var nM = Math.floor(nMS/(1000*60)) % 60;      var nS = Math.floor(nMS/1000) % 60;     if (nS<10)nS ="0" +nS     document.getElementById('txt').value=nH+":"+nM+":"+nS;  }  </script></head><body><form><input type="button" value="开始计时!" onClick="timedCount()" id="but"><input type="button" value="停止计时!" onClick="stopCount()"><input type="button" value="重置计时!" onClick="resetCount()"><input type="text" id="txt"></form></body></html>第二种var EndTime = new Date('${groupon.endTime}');var NowTime = new Date();var nMS = EndTime.getTime() - NowTime.getTime();$(document).ready(function(){if(nMS>1000){window.setInterval(showTime,1000);}else{$("#ctcontent").text("已过期!");}// setTimeout("showTime()",1000); });function showTime(){debuggernMS = nMS - 1000;var nD = Math.floor(nMS/(1000 * 60 * 60 * 24));var nH = Math.floor(nMS/(1000*60*60)) % 24;var nM = Math.floor(nMS/(1000*60)) % 60;var nS = Math.floor(nMS/1000) % 60;$("#ctday").text(nD);$("#cttime").text(nH+":"+nM+":"+nS);}


0 0
原创粉丝点击