event.which和event.keycode无法在Internet Explorer 10上用于退格按钮

问题描述:

我必须使用 JavaScript $跟踪字母键退格键 C $ C>。
我使用下面的代码来跟踪每个按键,但不幸的是,当我在 IE 中按退格按钮时我对此问题一无所知。

I have to track the alphabet keys and backspace key with JavaScript. I am using below written code to track every key press but unfortunately when i press backspace button in IE i gets nothing any idea regarding the issue.

    $('#crossword').delegate('.grid_input_holder','keypress',function(event){
            alert('keycode : '+event.keycode+' which : '+$(this).val( String.fromCharCode(event.which));
    });

提前致谢

如果你想支持IE并且你使用特殊键(比如 delete backspace )我建议改用 keydown / keyup

If you want to support IE and you use special keys (like delete and backspace) I suggest using keydown/keyup instead.


特殊键

资源管理器不会触发按键
事件删除,结束,输入,转义,
功能键,主页,插入,
pageUp / Down和tab。

Explorer doesn't fire the keypress event for delete, end, enter, escape, function keys, home, insert, pageUp/Down and tab.

如果你需要de选择这些密钥,帮自己一个忙,并搜索他们的keyCode onkeydown / up ,并忽略onkeypress和charCode。

If you need to detect these keys, do yourself a favour and search for their keyCode onkeydown/up, and ignore both onkeypress and charCode.

您可以阅读有关 检测击键的跨浏览器问题的更多信息(Quirksmode)

You can read more on cross browser issues of Detecting keystrokes (Quirksmode).

OR

Backspace的密钥代码将如果我们在文本框中已经有几个字符,请取值= 83

Key Code for Backspace will take the value = 83 if we already have a few characters in a Text Box .

密钥代码将be = 8 如果文本框中没有任何字符,我们正试图点击Backspace。

The Key Code will be = 8 if there are NO Characters in the Text Box and we are trying to Hit Backspace.