This article mainly introduces the use of KeyDown events to prevent user input concrete implementation, the need for friends can refer to the following
Understand the difference between the events of the next KeyDown: Occurs when a key is pressed when the control has focus KeyPress: Occurs when a key is pressed when the control has focus KEYUP: Occurs when a key is released when the control has focus 1, KeyPress is mainly used to receive letters, numbers and other ANSI characters. KeyDown and KeyUP event procedures can usually capture the keyboard except PRSCRN all keys (Special keys 2 for special keyboards are not discussed here, KeyPress can only capture single characters, KeyDown and KeyUP capture key combinations.) 3, KeyPress does not display the physical state of the keyboard (Shift key), but simply passes a character. KeyPress interprets the large and lowercase forms of each character as a different key code, that is, as two different characters. KeyDown and KeyUp cannot determine the size of key-value letters. KeyDown and KeyUp interpret the uppercase and lowercase forms of each character with two parameters: keycode-displays the physical keys (returns a and a as the same key) and shift-indicates the state of the SHIFT + key key and returns either A or a. 5, KeyPress does not distinguish between keypad and main keyboard numeric characters, KeyDown and KeyUp distinguish between keypad and main keyboard numeric characters. 6, KeyDown, KeyUp events occur when a key is pressed (KeyDown) or released (KEYUP). Because the keyboard usually press the key will be immediately released (this is different from the mouse), so the two events using which difference is not. Also, the up and the other two have a difference: to determine the state of the key modified must use up. We can use the KeyDown event to block user input, such as an input field can only enter the number keyboard number keys keycode [48-57] number key [96-105] Numeric keypad also allows backspace key deletion code as follows code as follows: var input = document.getElementById (' Number_ipt ') Input.onkeydown = function (e) { var keycode = e.keycode if (!isnumber (keycode)) return false } //Only numeric function isnumb ER (keycode) { //Digital if (keycode >= && keycode <=) return true //small numeric keypad if (ke Ycode >= && keycode <=) return true //backspace key if (KeyCode = 8) return true RET Urn false }