倒数计时类 <html><head><script type="text/javascript">...var Class = ...{ create: function() ...{ return function() ...{ this.initialize.apply(this, arguments); } }}//倒数计时类var Countdown = Class.create();Countdown.prototype = ...{ initialize: function(callback, frequency, elm) ...{ this.obj = document.getElementById(elm) || null; this.callback = callback; this.frequency = frequency; this.registerCallback(); }, //设置回调 registerCallback: function() ...{ var oCountdown = this; this.timer = setInterval(function()...{ oCountdown.onTimerEvent(); }, 1000); }, //停止倒数 Stop: function() ...{ clearInterval(this.timer); }, //设置回调函数 onTimerEvent: function() ...{ if (this.frequency-- <= 0) ...{ this.Stop(); this.Inset(0); this.callback(); } else ...{ this.Inset(this.frequency); } }, //把剩余时间显示到相应标签 Inset: function(n) ...{ if(this.obj) this.obj.innerHTML = n; }}</script></head><body>倒数剩下<span id="timeout">6</span>秒。<script type="text/javascript">...var timer = new Countdown(function()...{alert("时间到了")}, 6, 'timeout');</script><input name="" type="button" value="Stop" onClick="timer.Stop();"></body></html>