js實現倒計時效果


<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>倒計時效果</title>
<link rel="stylesheet" href="css/demo.css" />
</head>

<body>
<div class="content3">
<div class="time">距離春節時間還有<span id="LeftTime"></span></div>
</div>
<script>
function FreshTime()
{
var endtime=new Date("2017/1/28,0:0:0");//結束時間
var nowtime = new Date();//當前時間
var lefttime=parseInt((endtime.getTime()-nowtime.getTime())/1000);
var d=parseInt(lefttime/3600/24);
var h=parseInt((lefttime/3600)%24);
var hh=checkTime(h)
var m=parseInt((lefttime/60)%60);
var mm=checkTime(m)
var s=parseInt(lefttime%60);
var ss=checkTime(s)
document.getElementById("LeftTime").innerHTML=d+"天"+hh+"小時"+mm+"分"+ss+"秒";
function checkTime(i){
if (i<10){
i="0" + i;
}
return i;
}
if(lefttime<=0){
document.getElementById("LeftTime").innerHTML="團購已結束";
clearInterval(sh);
}
}
FreshTime();

var sh=setInterval(FreshTime,1000);
</script>
</body>
</html>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM