Ive got i problem.. Wheres the problem? A blog about Java and its related technologies, the best practices, algorithms, interview questions, scripting languages, and Python. About Me. Contact Us. The whole point of jQuery is that you don't have to worry about browser differences. I am pretty sure you can safely go with enter being 13 in all browsers. So with that in mind, you can do this:.
Mozilla Docs. There's a keypress event method. The Enter key's ascii number is 13 and is not dependent on which browser is being used. A minor extension of Andrea's answer above makes the helper method more useful when you may also want to capture modified enter presses i. For example, this variant allows binding like:. It took me a bit to figure out how to do this, and I am posting this simple yet complete example up here for the community. When pressing the "a" key on the keyboard not using caps lock , the result of char and key will be:.
We just launched W3Schools videos. Get certified by completing a course today! If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:.
Properties: constructor global ignoreCase lastIndex multiline source Methods: compile exec test toString. The value of key events which are caused by pressing or releasing printable keys in standard position is not compatible between browsers.
Google Chrome, Chromium and Safari must decide the value from the input character. If the inputting character can be inputted with the US keyboard layout, they use the keyCode value on the US keyboard layout. Starting in Firefox 15 Firefox See the following rules for details:. Starting in Firefox 60 Firefox Warning: The purpose of these new additional rules is for making users whose keyboard layouts map unicode characters to punctuation keys in a US keyboard layout can use web applications which support Firefox only with ASCII-capable keyboard layouts or just with a US keyboard layout.
Otherwise, the newly mapped keyCode values may be conflict with other keys. For example, if the active keyboard layout is Russian, the keyCode value of both the "Period" key and "Slash" key are KeyEvent.
If you need to distinguish those keys but you don't want to support all keyboard layouts in the world by yourself, you should probably use KeyboardEvent. The value of keyup event is 0x00 0. These keyCode values are the same as the Insert key's keyCode values. Chrome and Safari map them to the same keyCode values as Mac's keys.
0コメント