**這是Ext群里一位大蝦提供的解決方案。**
通常情況下,在窗口顯示時,也就是在窗口的show事件中,直接使用focus方法讓字段獲得焦點,會因為瀏覽器內部處理而丟失焦點。
解決辦法就是延遲執行focus,在API中,Ext.form.field.Base的focus方法的說明如下:
[focus](http://localhost/ext4/docs/index.html#%21/api/Ext.Component-method-focus)( [[Boolean](http://localhost/ext4/docs/index.html#%21/api/Boolean) selectText], [[Boolean](http://localhost/ext4/docs/index.html#%21/api/Boolean)/[Number](http://localhost/ext4/docs/index.html#%21/api/Number) delay] ) : [Ext.Component](http://localhost/ext4/docs/index.html#%21/api/Ext.Component)
Try to focus this component.
### Parameters
- selectText : [Boolean](http://localhost/ext4/docs/index.html#%21/api/Boolean) (optional)
If applicable, true to also select the text in this component
- delay : [Boolean](http://localhost/ext4/docs/index.html#%21/api/Boolean)/[Number](http://localhost/ext4/docs/index.html#%21/api/Number) (optional)
Delay the focus this number of milliseconds (true for 10 milliseconds).
### Returns
- [Ext.Component](http://localhost/ext4/docs/index.html#%21/api/Ext.Component)
The focused Component. Usually `this` Component. Some Containers maydelegate focus to a descendant Component ([Window](http://localhost/ext4/docs/index.html#%21/api/Ext.window.Window)s can do this through their[defaultFocus](http://localhost/ext4/docs/index.html#%21/api/Ext.window.Window-cfg-defaultFocus) config option.
方法帶兩個參數,第一個參數的作用是用來選中文本的,第二個參數就是延遲執行的時間,因而只要設置第二個參數,就可以實現效果了。
例如:
form.findField("第一個字段名字").focus(false,100);
這句中的form表示的是Ext.form.Basic的實例。在focus方法,設置了延遲時間為100微秒,也就是在延遲100微秒后才將焦點轉移到第一個輸入字段,這樣可以很好的解決該問題。
- 前言
- extjs 4 tree 的text不顯示
- 窗口顯示時讓字段獲得焦點
- 如何編寫一個使用Store更新復選框的CheckboxGroup的插件
- 如何了解事件中回調函數的參數
- 很多人需要的,帶時間的日期選擇器
- 一個網上找到的,在Grid中嵌套Grid的示例:Nested Grids Example
- 修改Ext.ux.GroupTabPanel讓它支持延遲渲染
- 初學者比較容易犯的布局錯誤(手風琴布局)
- Ext JS添加子組件的誤區
- 使用Ext JS,不要使用頁面做組件重用,盡量不要做頁面跳轉
- 【翻譯】十大要避免的Ext JS開發方法
- 一個不錯的擴展:Ext.ux.container.ButtonSegment
- 在VS2012中實現Ext JS的智能提示太簡單了
- 為什么要使用“var me=this”這樣的寫法
- 一個很不錯的支持Ext JS 4的上傳按鈕
- 【翻譯】熱門支持小提示:2013年12月
- 【翻譯】在Ext JS應用程序中使用自定義圖標
- 演練Ext JS 4.2自定義主題
- 【翻譯】培訓提示:解決常見編碼問題的簡單技巧
- 【翻譯】從Store生成Checkbox Group
- 【翻譯】將Ext JS Grid轉換為Excel表格
- 【翻譯】Ext JS 5:為不同設備設置不同的主題