本文主要是介绍js 促销倒计时,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
<div class="p-time fr">距离结束还有:<span class="promote_left" data-time="{$promote.end_date_format}" id="promote_time{$promote.id}"><strong>00</strong> 时
<strong>00</strong> 分
<strong>00</strong> 秒
</span></div>
<script type="text/javascript">
var time_html = "";
$(document).ready(function(){
setInterval("get_left_time()",1000);
});
function get_left_time()
{
$(".promote_left").each(function(){
//left_time: 2016/03/03 06:00:00
var left_time = $(this).attr("data-time");
var end_time= new Date(left_time);
var now_time = new Date();
var left_time =end_time.getTime() - now_time.getTime();
if (left_time < 0)
{
left_time = 0;
dateLeft = 0;
hourLeft = 0;
minuteLeft = 0;
secondLeft = 0;
}
else
{
dateLeft = Math.floor(left_time/1000/60/60/24);
hourLeft = Math.floor(left_time/1000/60/60%24);
minuteLeft = Math.floor(left_time/1000/60%60);
secondLeft = Math.floor(left_time/1000%60);
}
if(dateLeft>0)
{
time_html = "<strong>"+dateLeft+"</strong> 天"
}else
{
hourLeft = check_time(hourLeft);
minuteLeft = check_time(minuteLeft);
secondLeft = check_time(secondLeft);
time_html = "<strong>"+hourLeft+"</strong> 时";
time_html += "<strong>"+minuteLeft+"</strong> 分";
time_html += "<strong>"+secondLeft+"</strong> 秒";
}
$(this).html(time_html);
});
}
function check_time(i)
{
if (i < 10) {
i = "0" + i;
}
return i;
}
</script>
这篇关于js 促销倒计时的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!