<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>Jquery实现倒计时效果</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
var SysSecond;
var InterValObj;
$(document).ready(function() {
SysSecond = parseInt($("#remainSeconds").html()); //这里获取倒计时的起始时间
InterValObj = window.setInterval(SetRemainTime, 1000); //间隔函数,1秒执行
});
//将时间减去1秒,计算天、时、分、秒
function SetRemainTime() {
if (SysSecond > 0) {
SysSecond = SysSecond - 1;
var second = Math.floor(SysSecond % 60); // 计算秒
var minite = Math.floor((SysSecond / 60) % 60); //计算分
var hour = Math.floor((SysSecond / 3600) % 24); //计算小时
var day = Math.floor((SysSecond / 3600) / 24); //计算天
$("#remainTime").html(day + "天" + hour + "小时" + minite + "分" + second + "秒");
} else {//剩余时间小于或等于0的时候,就停止间隔函数
window.clearInterval(InterValObj);
//这里可以添加倒计时时间为0后需要执行的事件
}
}
</script>
</head>
<body>
<div id="remainSeconds" style="display:none">360000</div>
<div id="remainTime" style="font-size:20px;font-weight:800;color:#FF9900"></div>
</body>
</html>
//
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>
<script>
var totaltime=3600000;
var nowtime;
$(function(){
nowtime = window.setInterval(SetRemainTime, 1000); //间隔函数,1秒执行
});
function SetRemainTime(){
if(totaltime>0){
totaltime = totaltime - 1;
var second = Math.floor(totaltime % 60); // 计算秒
var minite = Math.floor((totaltime / 60) % 60); //计算分
var hour = Math.floor((totaltime / 3600) % 24); //计算小时
var day = Math.floor((totaltime / 3600) / 24); //计算天
$("#day").html(day);
$("hour").html(hour);
$("#minite").html(minite);
$("#second").html(second);
}else{
$("#day").html(0);
$("hour").html(0);
$("#minite").html(0);
$("#second").html(0);
}
}
</script>
</head>
<body>
<div id="day"></div>天<div id="hour"></div>时<div id="minite"></div>分<div id="second"></div>秒
</body>
</html>