简单JS倒计时
作者:互联网
<html> <head> <meta charset="UTF-8"> <title>简单时长倒计时</title> <SCRIPT type="text/javascript"> var maxtime = 60 * 5; //一个小时,按秒计算,自己调整! function CountDown() { if (maxtime >= 0) { minutes = Math.floor(maxtime / 60); seconds = Math.floor(maxtime % 60); msg = minutes.pad(2) + ":" + seconds.pad(2); document.all["timer"].innerHTML = msg; --maxtime; } else{ clearInterval(timer); alert("时间到,结束!"); } } Number.prototype.pad = function(size) { var s = String(this); while (s.length < (size || 2)) {s = "0" + s;} return s; } timer = setInterval("CountDown()", 1000); </SCRIPT> </head> <body> <div id="timer" style="color:red"></div> <div id="warring" style="color:red"></div> </body> </html>
标签:60,timer,JS,倒计时,pad,简单,maxtime,Math,size 来源: https://www.cnblogs.com/shary/p/14200386.html