您的位置:首页 > Web前端 > JavaScript

javascript实现倒计时

2008-07-23 13:24 141 查看
<!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html;charset=GBK"%>
<html xmlns="http://www.w3.org/1999/xhtml" lang="gbk">
<head>
</head>
<title> 倒计时效果 </title>
<meta http-equiv="content-type" content="text/html; charset=gbk" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<script language="JavaScript">
<!-- //
var startTime = new Date();
var EndTime=startTime.getTime()+6000*60*1000; //getTime返回的是毫秒数
function GetRTime(){
var NowTime = new Date();
var nMS =EndTime - NowTime.getTime();
var nD =Math.floor(nMS/(1000 * 60 * 60 * 24)) % 365;
var nH=Math.floor(nMS/(1000*60*60)) % 24;
var nM=Math.floor(nMS/(1000*60)) % 60;
var nS=Math.floor(nMS/1000) % 60;
document.getElementById("RemainD").innerHTML=nD;
document.getElementById("RemainH").innerHTML=nH;
document.getElementById("RemainM").innerHTML=nM;
document.getElementById("RemainS").innerHTML=nS;
if(nMS>5*59*1000&&nMS<=5*60*1000)
{
alert("还有最后五分钟!");
}
setTimeout("GetRTime()",1000);
}
window.onload=GetRTime;
// -->
</script>
</head>
<body>
<div id="CountMsg">倒计时还有:<strong id="RemainD"></strong><strong id="RemainD"></strong>天<strong id="RemainH"></strong>时

<strong id="RemainM"></strong>分<strong id="RemainS"></strong>秒</div>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: