很实用的网页js倒计时代码,这个倒计时能精确到秒钟,可根据自己的需求来自定义倒计时目标时间。
<head> <script language="JavaScript"> <!-- hide script from old browser var DifferenceHour = -1 var DifferenceMinute = -1 var DifferenceSecond = -1 var Tday = new Date("July 20, 2050 00:00:00") var daysms = 24 * 60 * 60 * 1000 var hoursms = 60 * 60 * 1000 var Secondms = 60 * 1000 var microsecond = 1000 function clock() {//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀) 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") // document.formnow.now.value = timevalue var convertHour = DifferenceHour var convertMinute = DifferenceMinute var convertSecond = DifferenceSecond var Diffms = Tday.getTime() - time.getTime() DifferenceHour = Math.floor(Diffms / daysms) Diffms -= DifferenceHour * daysms DifferenceMinute = Math.floor(Diffms / hoursms) Diffms -= DifferenceMinute * hoursms DifferenceSecond = Math.floor(Diffms / Secondms) Diffms -= DifferenceSecond * Secondms var dSecs = Math.floor(Diffms / microsecond) if(convertHour != DifferenceHour) document.formnow.dd.value=DifferenceHour if(convertMinute != DifferenceMinute) document.formnow.hh.value=DifferenceMinute if(convertSecond != DifferenceSecond) document.formnow.mm.value=DifferenceSecond document.formnow.ss.value=dSecs // document.formnow.Tnow.value= DifferenceHour DifferenceMinute + DifferenceSecond + dSecs setTimeout("clock()",1000) }//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀) // end hiding --> </script> </head> <body onload="clock();return true"> <a href="https://www.wuming.ren">武鸣人</a>,各种信息资源免费发布,分享励志语录经典短句,减肥健身常识,各种js特效代码。网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)<hr> <!--欢迎来到武鸣人信息资源平台,各种信息免费发布,资源共享合作共赢,分享互联网流行的励志语录经典短句,减肥健身健康小常识及打卡记录,收集各种js特效代码。--> <script type="text/javascript" src="https://www.wuming.ren/ad/tc.js"></script> <script type="text/javascript" src="https://www.wuming.ren/ad/a.js"></script> <form name="formnow"> 现在离2050年july 20还有 <input type="text" name="dd" size=4> 天 <input type="text" name="hh" size=4> 小时 <input type="text" name="mm" size=4> 分 <input type="text" name="ss" size=4> 秒 </form> </body>
本文来自武鸣人网站,转载请注明出处