将重点放在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() / code>方法接受
defer
作为参数,所以请尝试:
Note that ExtJS's focus()
method accepts defer
as an argument, so try that:
Ext.getCmp('first_name').focus(false, 200);