1 window.onload = function(){ 2 var uS = 604800; //后台提供 : 秒 3 var day=hour=minute=second=0, timer; 4 var demo = document.getElementById("demo"); 5 //秒数转为 日:时:分:秒 6 uS==0 || (uS<86400||(day=Math.floor(uS/86400), uS=uS%86400)) 7 && uS==0 || (uS<3600||(hour=Math.floor(uS/3600), uS=uS%3600)) 8 && uS==0 || (uS<60||(minute=Math.floor(uS/60), uS=uS%60)) 9 && uS==0 || (second=uS); 10 //计时器一只 11 timer = setInterval(function(){ 12 demo.innerHTML= "还剩 "+day+"天"+hour+"时"+minute+"分"+second+"秒"; 13 second!=0 ? second-- : 14 (second=59, minute!=0 ? minute-- : 15 (minute=59, hour!=0 ? hour-- : 16 (hour=23, day!=0 ? day-- : 17 (hour=minute=second=0, clearInterval(timer))))); 18 },1000); 19 }
1 <div id="demo"></div>
简洁明了,自己写的。
JS倒计时器一只
时间: 2024-10-25 10:48:20