倒計時 JS小例子
阿新 • • 發佈:2018-04-04
倒計時 jquery js倒計時 <span class="cd_item_txt" id="days">00</span></div>
<div class="cd_item cd_hour" ><span class="cd_item_txt" id="hours">00</span></div>
<div class="cd_item cd_minute"><span class="cd_item_txt" id="minutes">00</span></div>
<div class="cd_item cd_second"><span class="cd_item_txt" id="seconds">00</span></div></div>
<div class="cd_item cd_hour" ><span class="cd_item_txt" id="hours">00</span></div>
<div class="cd_item cd_minute"><span class="cd_item_txt" id="minutes">00</span></div>
<script type="text/javascript" src="js/jquery-1.9.1.min.js">
function leftTimer(year,month,day,hour,minute,second){ var leftTime = (new Date(year,month-1,day,hour,minute,second)) - (new Date()); //計算剩余的毫秒數 // alert(leftTime); var days = parseInt(leftTime / 1000 / 60 / 60 / 24 , 10); //計算剩余的天數 var hours = parseInt(leftTime / 1000 / 60 / 60 % 24 , 10); //計算剩余的小時 var minutes = parseInt(leftTime / 1000 / 60 % 60, 10);//計算剩余的分鐘 var seconds = parseInt(leftTime / 1000 % 60, 10);//計算剩余的秒數 days = checkTime(days); hours = checkTime(hours); minutes = checkTime(minutes); seconds = checkTime(seconds); document.getElementById("days").innerHTML = days; document.getElementById("seconds").innerHTML = seconds; document.getElementById("minutes").innerHTML = minutes; document.getElementById("hours").innerHTML = hours; } function checkTime(i){ //將0-9的數字前面加上0,例1變為01 if(i<10) { i = "0" + i; } return i; } //$seckill_time = ‘2018,04,04,10,00,00‘; setInterval("leftTimer({$seckill_time})",1000); //在這裏修改6個參數 ,根據後臺傳值 leftTimer(); <--秒殺時間js end-->倒計時 JS小例子