Kookjs 倒计时

/**
 * @function 倒计时器

 * @author Kyle
 * @belog Kookjs
 * @time 2008-12-17
 * @version 1.0
 */
/**
 *
 * @param perMS 间隔时间
 * @param timeOut 过期时间
 * @param inFn   间隔执行函数
 * @param endFn  过期执行函数
 */
function TimerOut(perMS,timeOut,inFn,endFn) {
    this.perMS = perMS;
    this.timeOut = timeOut;
    this.currTime = perMS;
    this.interval = false;
    this.inFn = inFn;
    this.endFn = endFn;

}
TimerOut.prototype.perFn = function() {
    this.currTime += this.perMS;
    var currTime = this.currTime;
    var timeOut = this.timeOut;
    if (currTime > timeOut) {
        window.clearInterval(this.interval);
        this.endFn();
    } else {
        this.inFn(currTime);
    }
};
TimerOut.prototype.start = function() {
    var thisp = this;
    this.interval = window.setInterval(function() {
        thisp.perFn();
    }, this.perMS);
};
//测试

//测试
var timer = new TimerOut(1000, 3000, function() {
    alert(1)
}, function() {
    alert('end');
});
timer.start();

文章出处:DIY部落(http://www.diybl.com/course/4_webprogram/asp.net/netjs/20090318/163153.html)
请使用浏览器的分享功能分享到微信等