简体   繁体   中英

Javascript onkeypress delete or dot

Is there any way to find out if the user pressed the delete key or dot? It has the same keycode in FireFox.

Here is a nice overview regarding browser behavior when it comes to keyboard events:

JavaScript Madness: Keyboard Events (it's quite recent, too: July 7, 2008)

Scroll down to to "3.2. Values Returned on Character Events", there is a table showing what different browsers do.

Bottom line is: It depends.

According to Detecting keystrokes , it is possible, provided that:

  • you search for the keyCode ( 8 for delete) onkeydown/up, and
  • ignore both onkeypress and charCode (Especially if you consider the fact that IE does not fire keypressed event, only key up/down).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM