您的当前位置:首页php+js实现倒计时功能

php+js实现倒计时功能

2020-11-27 来源:乌哈旅游

js部分

setInterval("time_controller()",1000);
function time_controller(){
 $(".time_val").each(function(){
 var time_id = "time_show_"+$(this).attr('for');
 var time_val= $(this).attr('value');
 $(this).attr('value',time_val-1);
 show_time(time_id,time_val*1000);
 });
}
function show_time(id,timestamp)
{
 var timer = document.getElementById(id);
 var str_time,int_day,int_hour,int_minute,int_second;
 var time_distance = timestamp;
 if(time_distance>0)
 {
 int_day=Math.floor(time_distance/86400000)
 time_distance-=int_day*86400000;
 int_hour=Math.floor(time_distance/3600000)
 time_distance-=int_hour*3600000;
 int_minute=Math.floor(time_distance/60000)
 time_distance-=int_minute*60000;
 int_second=Math.floor(time_distance/1000)

 if(int_hour<10)
 int_hour="0"+int_hour;
 if(int_minute<10)
 int_minute="0"+int_minute;
 if(int_second<10)
 int_second="0"+int_second;
 str_time="<b>剩余时间:"+int_day+"天"+int_hour+"小时"+int_minute+"分钟"+int_second+"秒</b>";
 timer.innerHTML=str_time;
 }else{
 timer.innerHTML="<b>剩余时间: 0天0小时0分钟0秒</b>";
 }
}


html部分,php 和 js 的时间倒计时

 <div class="time" id="time_show_{$list.cmd_id}"></div>
 <input type="hidden" class="time_val" for="{$list.cmd_id}" value="{$list.time_val}" />
显示全文