Skip to main content

js倒计时

<!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>
</head>

<body>

<span id="txt"></span>

<script type="text/javascript">

//日期加减
function ddd()
{
var d = new Date(2015,08,13); //传入的时间
var myDate =new Date(); //当前时间

interval = Math.abs( d.getTime() – myDate.getTime() ); //

day = Math.floor(interval / (86400000));
day_mod = (interval % (86400000));

hour = Math.floor(day_mod / (3600000));
hour_mod = (day_mod % (3600000));

minute = Math.floor(hour_mod / (60000));
minute_mod = (hour_mod % (60000));

second = Math.floor(minute_mod / (1000));

document.getElementById(‘txt’).innerHTML = ( jiao_huan(d.getTime(),myDate.getTime()) + day+’天’ + hour + ‘小时’ + minute + ‘分’ + second + ‘秒’)

setTimeout("ddd()",1000);
}

//交换
function jiao_huan(a,b)
{
if(a < b)
{
return ‘ – ‘;
}
return ”;
}
ddd();
</script>

</body>
</html>

本条目发布于2012年9月6日。属于Javascript分类。 编辑