关闭

js实现生日倒计时的代码一例

1272人阅读 评论(0) 收藏 举报
分类:
<html>
<head>
<title>生日倒计时_www.jbxue.com</title>
<b>今天距离2014年8月2日的生日还有</b><br>
<script language="JavaScript">
<!-- 隐藏脚本从旧的浏览器
var DifferHour = -1
var DifferMinute = -1
var DifferSecond = -1
var Tday1 = new Date("Aug 2, 2014 20:00:00")   //**倒计时时间-注意格式
var daysms = 24 * 60 * 60 * 1000
var hoursms = 60 * 60 * 1000
var Secondms = 60 * 1000
var microsecond = 1000
function clock()
{
    var time = new Date()
    var hour = time.getHours()
    var minute = time.getMinutes()
    var second = time.getSeconds()
    var timevalue = ""+((hour > 12) ? hour-12:hour)
    timevalue +=((minute < 10) ? ":0":":")+minute
    timevalue +=((second < 10) ? ":0":":")+second
    timevalue +=((hour >12 ) ? " PM":" AM")
    var convertHour = DifferHour
    var convertMinute = DifferMinute
    var convertSecond = DifferSecond
    var Diffms = Tday1.getTime() - time.getTime()
    DifferHour = Math.floor(Diffms / daysms)
    Diffms -= DifferHour * daysms
    DifferMinute = Math.floor(Diffms / hoursms)
    Diffms -= DifferMinute * hoursms
    DifferSecond = Math.floor(Diffms / Secondms)
    Diffms -= DifferSecond * Secondms
    var dSecs = Math.floor(Diffms / microsecond)
    if(convertHour != DifferHour) document.formnow.dd.value=DifferHour
    if(convertMinute != DifferMinute) document.formnow.hh.value=DifferMinute
    if(convertSecond != DifferSecond) document.formnow.mm.value=DifferSecond
        document.formnow.ss.value=dSecs
        document.formnow.ss.value=dSecs
// document.formnow.Tnow.value= DifferHour DifferMinute + DifferSecond + dSecs
setTimeout("clock()",1000)


}
//
隐藏-->
</script>
</head>
<body onload="clock();return true" text="red">
<!--显示出内容-->
<form name="formnow">
<input name="dd" type="text" style="border:0;" size=2>

<input name="hh" type="text" style="border:0;" size=2>
小时
<input name="mm" type="text" style="border:0;" size=2>

<input name="ss" type="text" style="border:0;" size=2>

</form>
<!--倒计时完成-->
</body>
</html>
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1321454次
    • 积分:13681
    • 等级:
    • 排名:第965名
    • 原创:24篇
    • 转载:690篇
    • 译文:0篇
    • 评论:139条
    文章分类
    最新评论