2011-03-11 78 views
1

我想知道當按鈕在extjs中失去焦點/模糊時,什麼事件/方法被觸發/調用。extjs - 當按鈕失去焦點時什麼事件/方法被觸發/調用?

我有一個菜單按鈕。當我點擊按鈕或菜單項以外的任何地方時,菜單關閉。所以我想知道的是調用menu.hide()方法以便隱藏菜單。

有沒有人有這方面的想法?我試着按鈕上的按鈕,但它沒有被解僱。

回答

0

感謝@mankz。只需在Ext.menu.MenuMgr中覆蓋onMouseDown()函數即可。雖然,要做到這一點,我不得不重新定義Ext.menu.MenuMgr

0
/** 
    * Try to focus this component. 
    * @param {Boolean} selectText (optional) If applicable, true to also select the text in this component 
    * @param {Boolean/Number} delay (optional) Delay the focus this number of milliseconds (true for 10 milliseconds) 
    * @return {Ext.Component} this 
    */ 
    focus : function(selectText, delay){ 
     if(delay){ 
      this.focusTask = new Ext.util.DelayedTask(this.focus, this, [selectText, false]); 
      this.focusTask.delay(Ext.isNumber(delay) ? delay : 10); 
      return this; 
     } 
     if(this.rendered && !this.isDestroyed){ 
      this.el.focus(); 
      if(selectText === true){ 
       this.el.dom.select(); 
      } 
     } 
     return this; 
    }, 

    // private 
    blur : function(){ 
     if(this.rendered){ 
      this.el.blur(); 
     } 
     return this; 
    }, 

有趣。當Component獲得焦點或失去焦點時,ExtJS顯然不會引發任何事件。可能它值得推翻。

+0

您好,非常感謝您的回覆。我重寫了Component的模糊方法來打印(使用console.log()),但它不打印任何東西。這意味着它不會去那裏。有任何想法嗎?問候 – user427969 2011-03-11 00:43:56

+0

奇怪。這意味着模糊函數在ExtJS的某處被編程調用;它不會自動從瀏覽器活動中調用。用Firebug,檢查「this.el.blur()」中的「el」是指什麼。你應該找到一種方法來附加onblur eventHandler。 – 2011-03-11 00:51:45

0

ExtJS Button爲此確切目的有一個名爲menuhide的事件。當附加到按鈕(假設有一個)的菜單被隱藏時會被觸發。該事件被調用參數(Button this, Menu menu)

ExtJS API documentation更多細節 - 按鈕事件menushowmenutriggeroutmenutriggerover,並且mouseout也可能證明是有用的。

+0

嗨,謝謝你的回覆。其實我想隱藏一個條件菜單。爲此,我從菜單的beforehide方法返回false(使用變量)。我想要做的是如果有人點擊按鈕和菜單之外,然後關閉菜單。所以我想我正在尋找其他方法。問候。 – user427969 2011-03-14 21:54:13

+0

因此,您要避免菜單自己隱藏,總是從菜單的beforehide事件返回false - 爲什麼?您試圖阻止哪些菜單隱藏案例? – Tommi 2011-03-15 05:40:51

相關問題