倒计时 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>
<script type="text/javascript" class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="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-->
共同学习,写下你的评论
评论加载中...
作者其他优质文章