Javascript e.keyCode doesn't catch Backspace/Del in IE

后端 未结 2 1483
误落风尘
误落风尘 2020-12-15 05:47

I\'m trying to catch the pressing event of Backspace and Delete keys using javascript/jQuery with this kind of code.

$(\"textarea[name=txt]\").keypress(funct         


        
相关标签:
2条回答
  • 2020-12-15 06:31

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

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

    0 讨论(0)
  • 2020-12-15 06:53

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

    Special keys

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

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

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

    0 讨论(0)
提交回复
热议问题