1. Monitor the keyboard event source and keyboard action to achieve different operations
<script language= "JavaScript" for= "document" event= "onkeydown" >
<!--
The names of the controls in the form are numbers such as: 1,2,3 ...
This makes it easier to categorize event sources in the case of more controls
var id=parseint (event.srcElement.name);
var keyID = Event.keycode;
if (id>6 && id<76) ... {//Use the name of the control in form to judge
if (event.keycode>=48 && event.keycode <= 53) ... {//keyboard traverse number key 0-5 key value
Event.srcElement.value = event.keycode-48;
event.keycode=9; Tab key; Go to the next item
}else if (event.keycode>=0x60 && event.keycode <= 0x65) ... {//keyboard digit number key 0-5 key value
Event.srcElement.value = event.keycode-0x60;
event.keycode=9;
PlaySound ();
}
if (Event.keycode ==13) ... {
Event.keycode = 9;
Document.form1.elements[id-1].focus ();
}
else ... {
if (event.keycode ==13 && event.srcelement.type!= ' Submit ') ... {
Event.keycode = 9;
}
}
-->
</script>
2. Use carriage return instead of the TAB key
<script language= "javascript" for= "document" event= "onkeydown" >
<!--
if (event.keycode==13 && event.srcelement.type!= ' button ' && event.srcelement.type!= ' Submit ' & & event.srcelement.type!= ' reset ' && event.srcelement.type!= ' textarea ' && event.srcelement.type! ='')
event.keycode=9;
-->
</script>
Attached: Key values corresponding to keyboard keys |
|
|
Value Description/R 0x1 left mouse button/R 0x2 right mouse button/R 0x3 CANCEL key/R 0x4 the middle mouse button/R 0x8 BACKSPACE key/R 0x9 TAB/R 0xC Clear Key/R 0xD ENTER-R 0x10 SHIFT key/R 0x11 CTRL key/R 0x12 MENU key/R 0x13 PAUSE key/R 0x14 CAPS LOCK key/R 0x1b ESC key/R 0x20 SPACEBAR key/R 0x21 PAGE up key/R 0x22 PAGE down key/R 0x23 End key/R 0x24 Home key/R 0x25 left ARROW key/R 0x26 up ARROW key/R 0x27 Right ARROW key/R 0x28 down ARROW key/R 0x29 SELECT key/R 0X2A PRINT Screen key/R 0X2B EXECUTE key/R 0x2c SNAPSHOT key/R 0x2d INSERT key/R 0x2e DELETE key/R 0x2f Help key/R 0x90 num LOCK key/R The A to Z key is the same as the ASCII code of the A–z letter: Value Description/R A Key/R B Key/R C Key/R D Key/R E Key/R F Key/R G Key/R H Key/R Key I/R J Key/R K Key/R L-key/R M Key/R N-key/R O-P/r P-R Bayi Q key/R R key S Key/R T Key/R U Key/R V-R W Key/R X Key/R Y-key/R Z Key/R The 0 to 9 keys are the same as the ASCII code of the digital 0–9: Value Description/R 48 0 Key/R 49 1 Key/R 50 2 key/R 51 3 Key/R 52 4 Key/R 53 5 key/R 54 6 Key/R 55 7 key/R 56 8 Key/R 57 9 Key/R The following constants represent keys on the numeric keypad: Value Description/R 0x60 0-R 0x61 1-R 0x62 2-R 0x63 3-R 0x64 4-R 0X65 5-R 0x66 6-R 0x67 7-R 0x68 8-R 0x69 9-R 0x6a multiplication SIGN (*) key/R 0x6b PLUS SIGN (+) key/R 0x6c ENTER-R 0X6D minus SIGN (–) Key/R 0x6e DECIMAL Point (.) Key/R 0x6f Division SIGN (/) key/R The following constants represent the function keys: Value Description/R 0x70 F1 key/R 0x71 F2 key/R 0x72 F3 key/R 0x73 F4 key/R 0x74 F5 key/R 0x75 F6 key/R 0x76 F7 key/R 0x77 F8 key/R 0x78 F9 key/R 0x79 F10 key/R 0X7A F11 key/R 0x7b F12 key/R 0x7c F13 key/R 0x7d F14 key/R 0x7E F15 key/R 0x7F F16 key/R |
|