First, we define a form with the following code:
The code is as follows |
Copy Code |
Ext.define (' Demo.view.Viewport ', { Extend: ' Ext.container.Viewport ', items:[{ Xtype: ' Form ', Title: ' ExtJS Monitor keyboard events ', WIDTH:500, height:400, Margin: ' 100 0 0 200 ', defaults:{ Xtype: ' TextField ', WIDTH:300, LABELWIDTH:120, Margin: ' 20 0 0 30 ' }, items:[{ Fieldlabel: ' username ', Name: ' username ' },{ Fieldlabel: ' Password ', Name: ' Password ', InputType: ' Password ', Change configuration entry must be set to True, default false Enablekeyevents:true }], bbar:[{ Text: ' Login ', Action: ' Login ' },{ Text: ' Reset ', Action: ' Reset ' }] }] }); |
Then, set the Listener event on the Password box, code:
The code is as follows |
Copy Code |
ext.define (' Demo.controller.Controller ', { Extend: ' Ext.app.Controller ', init: function () { this.control ({ ' viewport > form Textfield[name=password] ': { keypress:this.userlogin  &NBSP} }) }, userlogin: function (b,e,eopts) { //e.getkey () is the number that gets the key, and 13 is the return enter if ( E.getkey () = { ext.msg.alert (' Hint ', ' you have pressed the return key, you can submit the form for login here ... ') } } ); |
Enter a password, press ENTER, Pop-up prompts:
ExtJS keyboard Event details:
1. First you set the input box that you want to listen to to allow keyboard events (enablekeyevents:true) to be used, or the keyboard event is unavailable;
2. Use the Getkey () method to determine whether the key is set for yourself, the specific key number can refer to the ExtJS given API, and then do the specific action