<!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>jsdmeo</title> <script src="jquery-3.3.1.min.js"></script> </head> <body onLoad="leftTimer()"> 抢购倒计时: <p class="tit_right" style=""> <span id="h" style="">00</span> <span id="m" style="">00</span> <span id="s" style="">00</span> </p> <p style="" id="juli"></p> <script > function leftTimer(year,month,day,hour,minute,second){ var newDate = new Date(); var newDate1 = new Date(year,month-1,day,hour,minute,second); var leftTime = (new Date(year,month-1,day,hour,minute,second))-(new Date());//计算剩余的毫秒数 var days = parseInt(leftTime / 1000/60/60/24,10);//calcute left days var hours = parseInt(leftTime / 1000 / 60 / 60 % 24 , 10); //计算剩余的小时 var minutes = parseInt(leftTime / 1000 / 60 % 60, 10);//计算剩余的分钟 var seconds = parseInt(leftTime / 1000 % 60, 10);//计算剩余的秒数 if(seconds<0){ $(".tit_right").css('display','none'); $("#juli").text("开始抢购") }else{ days = fix(days,2) ; hours = fix(hours,2); minutes = fix(minutes,2); seconds = fix(seconds,2); setTimeout("leftTimer(2018,8,12,00,0,0)",1000); document.getElementById("h").innerHTML = hours; document.getElementById("m").innerHTML = minutes; document.getElementById("s").innerHTML=seconds; } } //fix 函数,将1-9的1位数转换成1-09格式format function fix(num ,length){ return (''+num).length < length ? ((new Array(length+1)).join('0')+num).slice(-length):''+num; } </script> </body> </html>