This is the code and browser screenshot. The first one is number, the second one is also number, but the third one is NaN.
I want to get a key combination, such as Alt 1...Alt 9 and then decrease the key value. Go to a number that corresponds to the value of the option of select
but it keeps reporting NaN
$(function(){
$(document).keydown(function(event){
if(event.keyCode <=57 && event.keyCode >= 49 && event.altKey){
var selectval = (event.keyCode - 48);
console.log(typeof(event.keyCode));
console.log(typeof(selectval));
console.log(selectval);
}
});
})
There’s nothing wrong with writing it in native language
Use event.ctrlKey, event.shiftKey, event.altKey to determine whether the ctrl key, shift key and alt key are pressed
After changing several environments, this situation finally occurred. They are all the highest version of Google. I don’t know how there are several computers without undefined
The keyCode received by the new variable is undefined;
As for why I don’t understand it yet, can someone please explain the mechanism
jQuery will help you with compatibility processing, please use
event.which
代替event.keyCode
.No need for jQuery: