当在焦点元素上按下逃生键时,不会引发键事件 [英] Key events are not raised when escape key is pressed on a focused element

查看:46
本文介绍了当在焦点元素上按下逃生键时,不会引发键事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道何时在输入元素上按下 Esc 键.在Chrome 47.0.2526.106 m上, Esc 键可将焦点移开,但JavaScript无法捕获 keyup keydown keypress 事件.

I want to know when the Esc key is pressed on an input element. On Chrome 47.0.2526.106 m, the Esc key removes the focus, but JavaScript cannot catch the keyup, keydown, or keypress events.

演示: https://jsfiddle.net/gstvj9uq/

$("input").keydown(function() {
  alert('keydown');
});

$("input").keyup(function() {
  alert('keyup');
});

$("input").keypress(function() {
  alert('keypress');
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text">

谁能给出解决方案来捕获输入上的Escape键的下/上/按下事件?IE 10可以捕获该事件.

Can anyone give a solution to catch Escape key down/up/press event on an input? IE 10 can catch the event, however.

推荐答案

有同样的问题,原来是vimium扩展.如果没有这一点,就不会把重点放在按下逃逸键上.

Had the same problem, turned out to be the vimium extention. Without that, focus is not lost on pressing escape.

请注意,不会触发keypress事件进行转义,只有keydown和keyup会触发

Note that the keypress event is never fired for escape, only keydown and keyup

这篇关于当在焦点元素上按下逃生键时,不会引发键事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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