效果圖: ...
<!DOCTYPE HTML> <html> <head> <meta charset=utf-8"/> <title>團購——限時搶</title> </head> <body> <div> <div class="time">還剩 <span id="LeftTime"></span></div> </div> <script> function FreshTime() { var endtime = new Date("2017/10/15,12:20:12");//結束時間 var nowtime = new Date();//當前時間 var lefttime = parseInt((endtime.getTime() - nowtime.getTime()) / 1000); d = parseInt(lefttime / (24 * 3600)); h = parseInt(lefttime /3600%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(function () { FreshTime() },500); </script>
</body> </html>
效果圖: