//一、HTML页面结构
<p class="limit-time"></p>
//二、JS
<script type="text/javascript">
function limitTime(time){
var seconds = time,
minutes = Math.floor(seconds / 60),
hours = Math.floor(minutes / 60),
days = Math.floor(hours / 24),
CDay = days,
CHour = hours % 24,
CMinute = minutes % 60,
CSecond = Math.floor(seconds % 60),
returnObj = {};
if(CDay < 10) {
CDay = '0' + CDay;
}
if(CHour < 10) {
CHour = '0' + CHour;
}
if(CMinute < 10) {
CMinute = '0' + CMinute;
}
if(CSecond < 10) {
CSecond = '0' + CSecond;
}
returnObj = {
CDay: CDay,
CHour: CHour,
CMinute: CMinute,
CSecond: CSecond
};
return returnObj;
}
var time = 86500;
function startTime(time){
if(time>0){
var obj = limitTime(time),
timeStr = obj.CDay+'<i>DAY(S)</i>'+obj.CHour+':'+obj.CMinute+':'+obj.CSecond;
$('.limit-time').html(timeStr);
time--;
setTimeout(function(){
startTime(time);
},1000);
}else{
$('.limit-time').addClass('end').next('a').html('ACTIVIDADE TERMINOU');
}
}
startTime(time);
</script>