I always thought the if & switch statements basically compared things the same way but in different formats. However, when I was trying to capture the backspace keycode the switch is the only one that picked up on a comparison. Why is this?
$(window).on('keydown', function (e) {
e.preventDefault();
if( e.KeyCode == 8 ) {
$('div').append('<p>if</p>');
}
switch (e.keyCode) {
case 8: // Backspace
$('div').append('<p>switch</p>');
break;
}
});
Aucun commentaire:
Enregistrer un commentaire