詳細設置的倒計時的js程式碼

來源:互聯網
上載者:User
關鍵字 網頁製作 Ajax JavaScript

<!-- 把如下代碼加入<head>區域中 -->
<script language="JavaScript">
<!-- //more javascript from HTTP://www.jzread.com
var DifferenceHour = -1
var DifferenceMinute = -1
var DifferenceSecond = -1
var Tday = new Date("Janu 1, 2006 23:59:59")
var daysms = 24 * 60 * 60 * 1000
var hoursms = 60 * 60 * 1000
var Secondm s = 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")
// document.formnow.now.value = timevalue
var convertHour = DifferenceHour
var convertMinute = Diff erenceMinute
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 -= DifferenceSecon d * Secondms
var dSecs = Math.floor(Diffms / microsecond)
if(convertHour != DifferenceHour) document.formnow.dd.va lue=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)
}
// end hiding -->

</script>

<!-- 修改<body>內容 -->
<body onload="clock();return true">
<!-- 把如下代碼加入<body>區域中 -->

<form name="formnow">
還剩<input type="text" name="dd" size=2> 天
<input type="text" name="hh" size=2> 小時
<input type="text" name="mm" size=2> 分
<input type="text" name="ss" size=2> 秒就到2006年1月1日 23:59:59啦!
</form>
說明:<br/>
各月份中英文對照<br/><br/>

一月 January<br/>

二月 February<br/>

三月 March<br/>

四月 April<br/>

五月 May
<br/>
六月 Jun<br/>

七月 July<br/>

八月 August<br/>

九月 September<br/>

十月 October<br/>

十一月 November<br/>

十二月 December

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.