<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>团购——限时抢</title><link rel="stylesheet" href="style.css" /></head><body><div class="content3"><div class="time">还剩 <span id="LeftTime"></span></div></div><style>div,img{ margin:0; padding:0; border:0;}.content3{ background:url(http://img1.sycdn.imooc.com//534d13940001063d12000398.jpg) no-repeat; width:1200px; height:398px; margin:0 auto; position:relative;}.time{ position:absolute; top:122px; left:46%; line-height:22px; font-size:14px;}</style><script>window.onload=function(){ FreshTime();}function FreshTime(){ var endtime=new Date("2016/12/15,12:20:00");//结束时间 var nowtime = new Date();//当前时间 var lefttime=parseInt((endtime.getTime()-nowtime.getTime())/1000); d= parseInt(lefttime/(60*60*24)); h= parseInt(lefttime/(60*60)&24); m= parseInt(lefttime/60&60); s= parseInt(lefttime&60); document.getElementById("LeftTime").innerHTML=d+"天"+h+"小时"+m+"分"+s+"秒"; if(lefttime<=0){ document.getElementById("LeftTime").innerHTML="团购已结束"; clearInterval(sh); } var sh sh=setInterval("FreshTime()",500);} </script></body></html>
1 回答
已采纳
李晓健
TA贡献1036条经验 获得超461个赞
function FreshTime(){ var endtime=new Date("2016/12/15,12:20:00");//结束时间 var nowtime = new Date();//当前时间 var lefttime=parseInt((endtime.getTime()-nowtime.getTime())/1000); var d = parseInt(lefttime/(60*60*24)); var tempLeft = lefttime % (60*60*24); var h = parseInt(tempLeft /(60*60)); tempLeft = tempLeft % (60*60); var m = parseInt(tempLeft / 60); tempLeft = tempLeft % 60; var s = tempLeft document.getElementById("LeftTime").innerHTML=d+"天"+h+"小时"+m+"分"+s+"秒"; if(lefttime<=0){ document.getElementById("LeftTime").innerHTML="团购已结束"; clearInterval(sh); }
这样不知道你能不能看明白
添加回答
举报
0/150
提交
取消