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=”timeDate”>载入倒计时…</span><br />

<script type=”text/javascript”>
var now = new Date();
var tim=”03/04/2008 11:28:00″;
function createtime(){
????var grt= new Date(tim);
????now.setTime(now.getTime()+1000);
????if (grt < now) {
????????document.getElementById(“timeDate”).innerHTML = “本期投票结束!”;????
????????return;
????}
????else {
????????days = (grt – now) / 1000 / 60 / 60 / 24;
????????dnum = Math.floor(days);//日
????????hours = (grt – now) / 1000 / 60 / 60 – (24 * dnum);
????????hnum = Math.floor(hours);//小时
????????if (String(hnum).length == 1) {
????????????hnum = “0” + hnum;
????????}
????????minutes = (grt – now) / 1000 / 60 – (24 * 60 * dnum) – (60 * hnum);
????????mnum = Math.floor(minutes);//分钟
????????if (String(mnum).length == 1) {
????????????mnum = “0” + mnum;
????????}
????????seconds = (grt – now) / 1000 – (24 * 60 * 60 * dnum) – (60 * 60 * hnum) – (60 * mnum);
????????snum = Math.round(seconds);//秒
????????if (String(snum).length == 1) {
????????????snum = “0” + snum;
????????}
????????document.getElementById(“timeDate”).innerHTML = dnum + “天”+ hnum + “小时” + mnum + “分钟” + snum+ “秒”;
????}
}
setInterval(“createtime()”,1000);????????????????
</script>
</body>
</html>

赞(0) 打赏
未经允许不得转载:WEB前端开发 » js倒计时实例

评论 1

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #-49

    错误一大堆,不知道自己测试过没有,

    dyfire9年前 (2010-08-22)回复

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏