将焦点设置在 Extjs 文本字段上 [英] Set focus on Extjs textfield
本文介绍了将焦点设置在 Extjs 文本字段上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前我在设置 extjs 文本字段的焦点时遇到问题.当表单显示时,我想将焦点设置为名字文本框,我尝试使用内置函数 focus() 但仍然无法使其工作.很高兴看到您的建议.
Currently I got problem with setting focus on extjs textfield. When form show, I want to set focus to First name text box and I try to use build in function focus() but still can't make it work. I am happy to see your suggestion.
var simple = new Ext.FormPanel({
labelWidth: 75,
url:'save-form.php',
frame:true,
title: 'Simple Form',
bodyStyle:'padding:5px 5px 0',
width: 350,
defaults: {width: 230},
defaultType: 'textfield',
items: [{
fieldLabel: 'First Name',
name: 'first',
id: 'first_name',
allowBlank:false
},{
fieldLabel: 'Last Name',
name: 'last'
},{
fieldLabel: 'Company',
name: 'company'
}, {
fieldLabel: 'Email',
name: 'email',
vtype:'email'
}, new Ext.form.TimeField({
fieldLabel: 'Time',
name: 'time',
minValue: '8:00am',
maxValue: '6:00pm'
})
],
buttons: [{
text: 'Save'
},{
text: 'Cancel'
}]
});
simple.render(document.body);
推荐答案
有时在聚焦时添加一点延迟会有所帮助.这是因为某些浏览器(肯定是 Firefox 3.6)需要一些额外的时间来呈现表单元素.
Sometimes it helps to add a little delay when focusing. This is because certain browsers (Firefox 3.6 for sure) need a bit of extra time to render form elements.
注意 ExtJS 的 focus()
方法接受 defer
作为参数,所以试试:
Note that ExtJS's focus()
method accepts defer
as an argument, so try that:
Ext.getCmp('first_name').focus(false, 200);
这篇关于将焦点设置在 Extjs 文本字段上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文