Trying to find out if there is an error in jQuery or if I am doing something

$(document).keydown(function (event)
    {
    alert(event.which);
    });

For a semicolon key, ;this gives 59 in Firefox and 186 in Chrome. However, the jQuery help page for the keydown event says:

"While browsers use different properties to store this information, jQuery normalizes the .which property so that you can reliably use it to extract the key code. This code corresponds to a key on the keyboard, including codes for special keys such as arrows."

Did I miss something?

+5
source share
4 answers

which " ", , keyCode charCode. "", jQuery.

which , , , , . .

+4

A Google , . Firefox.

+1

jQuery, keydown , .

0
source

Here is the fullness of the "normalization" jQuery does:

if ( event.which == null ) {
    event.which = original.charCode != null ? original.charCode : original.keyCode;
}

Looks like it just gets keyCode, if it charCodedoesn't exist. And charCodeused only if event.whichit does not exist yet. It does not change the numbers around to make them consistent.

0
source

All Articles