为什么keypress不处理删除键和退格键 [英] Why doesn't keypress handle the delete key and the backspace key

查看:963
本文介绍了为什么keypress不处理删除键和退格键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是在问这个因为我需要一个工作场所。我有一个工作正常,但我想知道为什么它没有。这是javascript中的错误(或JQuery,因为我使用的是JQuery .keypress 处理程序),还是有一个特定原因导致这种情况发生?

I'm not asking this because I need a work-a-around. I have one that works fine, but I want to know WHY it doesn't. Is this bug in javascript (or JQuery because I was using the JQuery .keypress handler) or is there a specific reason why this is so?

提前致谢。

推荐答案

keypress event用于处理用户键入的字符,而不是检测键盘活动,delete和backspace键不生成字符。有些浏览器在某种程度上模糊了这一行,但一般原则是 keyup keydown 事件可用于检测任何密钥按下并告诉你它是哪个键,而 keypress 用于检测正在键入的实际字符。

The keypress event is designed for handling a character typed by the user rather than detecting keyboard activity and the delete and backspace keys do not generate characters. Some browsers blur this line somewhat but the general principle is that the keyup and keydown events are there to detect any key being pressed and telling you about which key it is while keypress is for detecting an actual character being typed.

这篇关于为什么keypress不处理删除键和退格键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆