How do I capture the backspace key in IE8 with jquery?

烂漫一生 提交于 2019-12-08 01:38:39

问题


I've got a simple javascript keydown event coded via jquery. The event should just alert the key that is "down." This works for most keys but not the backspace key in Internet Explorer. I read that IE messes this up on the keypress event but was supposed to work for the keydown and keyup events.

Is there anything I can do via jquery to capture the backspace in IE? The version of IE I'm currently testing in is:

8.0.7600.16385

        $('.AddressField').bind("keydown", function (e) {
            alert(e.keyCode);
        });

回答1:


use which:

  $('.AddressField').keypress(function(e){
       alert(e.which);
   });



回答2:


keyCode property is not available in IE. In IE you must use which property.



来源:https://stackoverflow.com/questions/3305480/how-do-i-capture-the-backspace-key-in-ie8-with-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!