2012-08-12 15 views
1

我試圖調用一個函數,當鼠標上升的goog.ui.Control一個子類以上:當鼠標在goog.ui.Control上方時,如何調用函數?

/** @override */ 
myapp.MyButton.prototype.handleMouseUp = 
    function(e) { 
    goog.base(this, 'handleMouseUp', e); 
    alert('Woof!'); 
} 

然而,當我點擊我的按鈕,沒有警報顯示出來。爲什麼不?當鼠標點擊後揚起時,handleMouseUp會不會被調用?

回答

1

的源代碼goog.ui.Control包含以下注釋:

所有控件都分別派出顯示,隱藏ENTER,離開,操作事件的顯示,隱藏,鼠標懸停,鼠標移開,以及用戶操作。

要看看到底哪些事件將被指派的各種動作,看看在goog.ui.Control demo,其中有一個現場活動日誌。

爲了使另外的過渡事件,goog.ui.Control包括以下方法:

/** 
* Enables or disables transition events for the given state(s). Controls 
* handle state transitions internally by default, and only dispatch state 
* transition events if explicitly requested to do so by calling this method. 
* @param {number} states Bit mask of {@link goog.ui.Component.State}s for 
*  which transition events should be enabled or disabled. 
* @param {boolean} enable Whether transition events should be enabled. 
*/ 
goog.ui.Control.prototype.setDispatchTransitionEvents = function(states, 
    enable) { 
    this.statesWithTransitionEvents_ = enable ? 
     this.statesWithTransitionEvents_ | states : 
     this.statesWithTransitionEvents_ & ~states; 
}; 

例如,你可以做到以下幾點,以使所有狀態轉換事件。

var myButton = new myapp.MyButton(); 
myButton.setDispatchTransitionEvents(goog.ui.Component.State.ALL, true); 

現在當鼠標按鍵時的activate事件將被分派並在釋放鼠標按鈕deactivate事件將被分派。

請參閱goog.ui.Button demo(特別是靠近頁面底部的組合切換按鈕)。

相關問題