为什么不使用jquery keypress事件检测退格? [英] Why isn't backspace being detected using jquery keypress event?

查看:159
本文介绍了为什么不使用jquery keypress事件检测退格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么不使用jquery keypress事件检测退格?

Why isn't backspace being detected using jquery keypress event?

$("#field").keypress(function(event){alert(event.which);});


推荐答案

keypress事件是(在其原始IE中)表单,以及在Safari / Chrome中)关于添加到文本字段的实际字符。退格键显然不会在字段值中添加新字符,因此它不会导致按键事件。

The "keypress" event is (in its original IE form, and in Safari/Chrome) about an actual character being added to a text field. The backspace key clearly does not add a new character to the field value, so it causes no keypress event.

Firefox和Opera对于生成输入更加不知所措事件。

Firefox and Opera are a little more willy-nilly about generating typing events.

PPK( quirksmode 认为IE和Webkit行为是明智的行为,我非常同意。

PPK (quirksmode) considers the IE and Webkit behaviors to be the sensible ones, and I pretty much agree.

这篇关于为什么不使用jquery keypress事件检测退格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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