Ext监控回车按键
listeners : {
specialkey : function(field, e) {
if (e.getKey() == Ext.EventObject.ENTER) {
searchByFilter();
}
}
}
这是以监听器的方式添加监听事件,还有一种方法与此差不多:
keys : {
key : Ext.EventObject.ENTER,
fn : function(btn, e) {
searchData();
}
}
比如,我想设置在表单内单击回车执行submit提交,就可以这样做,下面是一个实例:
01 var loginForm = new Ext.form.FormPanel({
02 labelWidth : 80,
03 frame : true,
04 title : ‘用户登陆’,
05 bodyStyle : ‘padding:5px 5px 0′,
06 width : 370,
07 layout : ‘form’,
08 onSubmit : Ext.emptyFn,
09 defaultType : ‘textfield’,
10 submit : function() {
11 loginForm.getForm().getEl().dom.action = BP
12 + ‘j_acegi_security_check’;
13 loginForm.getForm().getEl().dom.submit();
14 },
15 items : [{
16 fieldLabel : '帐户',
17 name : 'j_username',
18 width : 200,
19 allowBlank : false,
20 vtypeText : '帐户不能为空',
21 validateOnBlur:true,
22 tabIndex : 1
23 }, {
24 fieldLabel : '密码',
25 width : 200,
26 validateOnBlur:true,
27 name : 'j_password',
28 inputType : 'password',
29 tabIndex : 2
30 }],
31 keys:{
32 key:Ext.EventObject.ENTER,
33 fn:function(btn,e){
34 loginForm.getForm().submit();
35 }
36 },
37 buttons : [{
38 text : '登陆',
39 type : 'submit',
40 tooltip : 'Login',
41 clickEvent : 'click',
42 handler : function() {
43 loginForm.getForm().submit();
44
45 }
46
47 }]
48 });
02 labelWidth : 80,
03 frame : true,
04 title : ‘用户登陆’,
05 bodyStyle : ‘padding:5px 5px 0′,
06 width : 370,
07 layout : ‘form’,
08 onSubmit : Ext.emptyFn,
09 defaultType : ‘textfield’,
10 submit : function() {
11 loginForm.getForm().getEl().dom.action = BP
12 + ‘j_acegi_security_check’;
13 loginForm.getForm().getEl().dom.submit();
14 },
15 items : [{
16 fieldLabel : '帐户',
17 name : 'j_username',
18 width : 200,
19 allowBlank : false,
20 vtypeText : '帐户不能为空',
21 validateOnBlur:true,
22 tabIndex : 1
23 }, {
24 fieldLabel : '密码',
25 width : 200,
26 validateOnBlur:true,
27 name : 'j_password',
28 inputType : 'password',
29 tabIndex : 2
30 }],
31 keys:{
32 key:Ext.EventObject.ENTER,
33 fn:function(btn,e){
34 loginForm.getForm().submit();
35 }
36 },
37 buttons : [{
38 text : '登陆',
39 type : 'submit',
40 tooltip : 'Login',
41 clickEvent : 'click',
42 handler : function() {
43 loginForm.getForm().submit();
44
45 }
46
47 }]
48 });