放飞自我 LET DREAMS FLY

[f]计时器

// 计时器
    function Timer(ele) {
        this._mStr = '';
        this._sStr = '';
        this._m = 0;
        this._s = 0;
        this._setTimer;
        this._init = function () {
            var self = this;
            self._setTimer = setInterval(function() {
                if (self._s >= 59) {
                    self._m += 1;
                    self._s = 0;
                } else {
                    self._s += 1;
                }

                self._sStr = self._s < 10 ? '0'+self._s : self._s;
                self._mStr = self._m < 10 ? '0'+self._m : self._m;


                $(ele).val(self._mStr+':'+self._sStr);
            }, 1000);
        };
        this._clear = function () {
            clearInterval(this._setTimer);
        };

        this._init();

    }

 

posted on 2017-08-18 15:47  niuben  阅读(139)  评论(0编辑  收藏  举报

导航