HTML (index.html):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <span id= 'clock' ></span> <script type= "text/javascript" > var reciprocalboxy = new function () { return { endDay : new Date( "2030/1/1 00:00:00" ), show : function () { var today = new Date(); var timeRemain = this .endDay - today; var D = parseInt(timeRemain/1000/60/60/24); var h = parseInt((timeRemain/1000/60/60)%24); var m = parseInt((timeRemain/1000/60)%60); var s = parseInt((timeRemain/1000)%60); document.getElementById( 'clock' ).innerHTML = D + "日" + h + "點" + m + "分" + s + "秒" ; }, init : function () { this .show(); window.setInterval( function () { reciprocalboxy.show(); }, 1000); } }; }; reciprocalboxy.init(); </script> |
1734日18點2分45秒
說明:
簡易倒數計時器範例。