JS get keyboard pressed key values are Event.keycode,event.charcode and Event.which
which
Google Chrome is compatible with Event.keycode,event.charcode and Event.which.
Firefox browser to event.keycode part of the key value, such as the next key (37,38,39,40), enter key (34), PgUp (PgDn), and other parts of the effective, the number keys, the letter key is invalid.
Event.which is also part of the key value valid, such as the letter key, number keys, enter key, backspace key and so on, on the next key, PgUp (), PgDn (34) key is invalid.
Event.charcode is also valid for some key values, such as the letter key, the number key, the BACKSPACE key and so on, on the ENTER key, the next key, PgUp (), PgDn (34) key is invalid.
In Internet Explorer, IE8 and the following browsers are not valid for Event.charcode, Event.keycode and Event.which are available for most key values, but few can be obtained
Network View said Event.which will Event.keycode and Event.charcode standardized. But there is a difference in reality.
So it's generally written in a compatible way:
e.keycode| | e.which| | E.charcode;
jquery API Address: http://api.jquery.com/event.which/
The following example shows how a query restricts text boxes to enter only numbers and decimal points
$(function(){ /*JQuery limit text box can only enter numbers*/ $(". Numtext "). KeyUp (function(){ $( This). Val ($ ( This). Val (). replace (/[^0-9]/g, ")); }). bind ("Paste",function(){//ctr+v Event Handling$( This). Val ($ ( This). Val (). replace (/[^0-9]/g, ")); }). css ("Ime-mode", "disabled");//CSS Settings ime not available /*JQuery limit text box can only enter numbers and decimal points*/ $(". Numdectext "). KeyUp (function(){ $( This). Val ($ ( This). Val (). replace (/[^0-9.] /g, ")); }). bind ("Paste",function(){//ctr+v Event Handling$( This). Val ($ ( This). Val (). replace (/[^0-9.] /g, ")); }). css ("Ime-mode", "disabled");//CSS Settings ime not available});
The KeyCode table is as follows:
JS get keyboard pressed key value Event.keycode,event.charcode,event.which compatibility