Preface
We often use key combinations, such as alt+f4, crrtl+enter. There will also be such demands in development.
Key combination type
Individual combination, two-key combination, three-key combination
Ideas
1. Get the keys on the keyboard
2. Block the default behavior on the browser
3. Execute custom js functions
Code example
= function(e) { var keyCode = || || ; var altKey = ; if(altKey && keyCode == 112) { alert("Key combination successful") } (); return false; }
Disassembly
|| ||
Google Chrome is compatible with both.
Firefox browser is valid for some key values, such as the upper and lower left and right keys (37, 38, 39, 40), enter key (13), PgUp (33), PgDn (34), etc., and is invalid for numeric keys and letter keys.
It is also valid for some key values, such as letter keys, numeric keys, enter keys, Backspace keys, etc., and is invalid for up and down left and right keys, PgUp(33), PgDn(34) keys.
It is also valid for some key values, such as letter keys, numeric keys, Backspace keys, etc., and is invalid for enter keys, up and down left and right keys, PgUp(33), PgDn(34) keys.
In ie browser, IE8 and below browsers are invalid and can be obtained for most key values, but a few of them cannot be obtained.
Therefore, this writing method is compatible writing method.
,,,
Used to monitor alt, shift, ctrl, and meta keys on the keyboard. When these keys are pressed, the value will become true.
()
The default events are blocked, and the processing methods are not very consistent under W3C standards and IE. The execution of the() method and the = false attribute are respectively. Of course, if you use jquery and other class libraries, you only need to write a () to help you achieve compatibility.
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.