2012-05-15 31 views
0

我想創建一個簡單的進度小部件。但我越來越_showProgress不是功能錯誤一次又一次。jQuery UI小工具無法找到封閉的功能

(function ($, undefined) { 
    $.widget("AOne.ProgressBar", { 

     options: { max: 100, min: 0, current: 0, time: 1000, stepWidth: 1 }, 

     innerDiv: $("<div></div>").css({ overflow: 'hidden', clear: 'both', 
         height: '10px', width: '0px', 
         background: 'transparent url("Progress.gif") repeat-x 
         scroll left center' }).html("&nbsp;"), 

     _create: function() { 
      this.element.append(this.innerDiv); 
      maxWidth = this.element.outerWidth(); 
      this.options.stepWidth = maxWidth/this.options.max; 
     }, 

     _init: function() { 
      this.intervalId = setInterval(function() { 
       this._showProgress(); 
      }, 
      this.options.time); 
     }, 

     _showProgress: function() { 
      this.options.current += 1; 

      if (this.options.current < this.options.max) { 
       this.innerDiv.css({ width: this.options.stepWidth * 
               this.options.current + 'px' }); 
      } else { 
       window.clearInterval(this.intervalId); 
      } 
     }, 

     _setOption: function (key, value) { 
      $.Widget.prototype._setOption.apply(this, arguments); 
     }, 

     destroy: function() { 
      $.Widget.prototype.destroy.call(this); 
     } 
    }); 
})(jQuery); 

回答

1

難道這是一個範圍問題嗎?試試這個:

_init: function() { 
    that = this; 
    this.intervalId = setInterval(function() { 
     that._showProgress(); 
    }, 
    this.options.time); 
}, 
+0

在這個上浪費了2個小時。你很酷!!! – TheVillageIdiot