dimanche 24 janvier 2016

Switch statement works with backspace KeyCode, if statement does not?

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?

http://ift.tt/1Vinye9

$(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