简体   繁体   English

显示jQuery通知时如何检测Esc键按下

[英]How to detect esc key press while showing jquery notification

I want to detect the key event of escape while displaying the jquery notification. 我想在显示jquery通知时检测转义的关键事件。 But as this is blocking the input I'm unable to detecting key board event while noty is showing. 但是由于这阻塞了输入,因此在显示Noty时我无法检测到键盘事件。

$(document).keyup(function(e) {

  if (e.keyCode == 27) { 
     //your codes 
  }   

});

Use This Code It Works Everywhere: 使用此代码可在任何地方使用:

// define a handler
function doc_keyUp(e) {
    if (e.keyCode == 27) {//27 is Esc KeyCode
    alert('Escape Key Has Been Pressed!');
    }
}
// register the handler 
document.addEventListener('keyup', doc_keyUp, false);

You can use onkeyup to pass event handler like- 您可以使用onkeyup传递事件处理程序,例如-

<input type="text" onkeyup="YourKeyupHandler(event)">

Now you can implement function like- 现在,您可以实现以下功能:

function YourKeyupHandler(event) {
    event = event || window.event || event.srcElement;
    if (event.keyCode == 27) {
        //here you can do whatever you want
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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