js倒计时代码 适合于促销-倒计时代码

时间:2021-06-26 15:14:20
<div class="tiem_price clearfix fonts" style="margin-top:15px;">
<div class="clockContainer clockContainer1 fl relative" id="38zhe"> <span class="day fl timer">00</span><em class="tag fl">天</em> <span class="hour fl timer">00</span><em class="tag fl">时</em> <span class="minute fl timer">00</span><em class="tag fl">分</em> <span class="second fl timer">00</span><em class="tag fl">秒</em> </div>
<div class="youhuiPrice relative fr">原价:3800元/次</div>
</div>

 

<script>
$(function(){
countDown("2016/3/3 12:00:00","#38zhe");
countDown("2016/3/31 12:00:00","#0tuo");
});
</script>
js 方法
function countDown(time,id){
var day_elem=$(id).find('.day');
var hour_elem=$(id).find('.hour');
var minute_elem=$(id).find('.minute');
var second_elem=$(id).find('.second');
var end_time = new Date(time).getTime();
var sys_second = (end_time-new Date().getTime())/1000;
var timer = setInterval(function(){
if(sys_second>1) {
sys_second-=1;
var day=Math.floor((sys_second/3600)/24);
var hour=Math.floor((sys_second/3600)%24);
var minute=Math.floor((sys_second/60)%60);
var second=Math.floor(sys_second%60);
$(day_elem).text(day);
$(hour_elem).text(hour<10?"0"+hour:hour);
$(minute_elem).text(minute<10?"0"+minute:minute);
$(second_elem).text(second<10?"0"+second:second);
}
else {
clearInterval(timer);
}
}, 1000);
}