ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
**这是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微秒后才将焦点转移到第一个输入字段,这样可以很好的解决该问题。