HTML (index.html):
<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>範例:
說明:
簡易倒數計時器範例。