窗口显示时让字段获得焦点

这是Ext群里一位大虾提供的解决方案。

通常情况下,在窗口显示时,也就是在窗口的show事件中,直接使用focus方法让字段获得焦点,会因为浏览器内部处理而丢失焦点。


解决办法就是延迟执行focus,在API中,Ext.form.field.Base的focus方法的说明如下:

( [Boolean selectText], [Boolean/Number delay] ) : Ext.Component

Try to focus this component.

Parameters

  • selectText : Boolean (optional)

    If applicable, true to also select the text in this component

  • delay : Boolean/Number (optional)

    Delay the focus this number of milliseconds (true for 10 milliseconds).

Returns

  • Ext.Component

    The focused Component. Usually this Component. Some Containers maydelegate focus to a descendant Component (Windows can do this through theirdefaultFocus config option.

方法带两个参数,第一个参数的作用是用来选中文本的,第二个参数就是延迟执行的时间,因而只要设置第二个参数,就可以实现效果了。


例如:

form.findField("第一个字段名字").focus(false,100);

这句中的form表示的是Ext.form.Basic的实例。在focus方法,设置了延迟时间为100微秒,也就是在延迟100微秒后才将焦点转移到第一个输入字段,这样可以很好的解决该问题。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值