首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

js兑现倒计时

2012-11-08 
js实现倒计时htmlheadtitle倒计时/title!--以下为css样式--style type text/css.daojishi

js实现倒计时

<html><head><title>倒计时</title><!--以下为css样式--><style type= "text/css">.daojishi h2{ font-family:Helvetica, Microsoft YaHei, Arial, sans-serif; font-size:14px;margin-bottom:5px; color:#151515;}.daojishi #timer{font-family:Helvetica, Microsoft YaHei, Arial, sans-serif; font-size:14px;color:#151515;font-weight:bold;}</style><script type = "text/javascript" src = "timer.js"></script></head><body onload = "timer()"><div class = "daojishi"><h2>剩余时间为:</h2><div id = "timer"></div></div></body></html>


timer.js

 

function timer(){var ts = (new Date(2012, 11, 11, 9, 0, 0)) - (new Date());//计算剩余的毫秒数var dd = parseInt(ts / 1000 / 60 / 60 / 24, 10);//计算剩余的天数var hh = parseInt(ts / 1000 / 60 / 60 % 24, 10);//计算剩余的小时数var mm = parseInt(ts / 1000 / 60 % 60, 10);//计算剩余的分钟数var ss = parseInt(ts / 1000 % 60, 10);//计算剩余的秒数dd = checkTime(dd);hh = checkTime(hh);mm = checkTime(mm);ss = checkTime(ss);document.getElementById("timer").innerHTML = dd + "天" + hh + "时" + mm + "分" + ss + "秒";setInterval("timer()",1000);}function checkTime(i)              {                 if (i < 10) {                     i = "0" + i;                  }                 return i;              }  


2楼emoven3天前 15:00
Re: lwcumt3天前 16:18
回复emovenn共同学习!
1楼wutao1990083天前 13:19
e
Re: lwcumt3天前 14:50
回复wutao199008nwhat is the meaning of the word 'e'?nI guess you are hungry.("饿")

热点排行