【问题标题】:how to get the pressed key with jquery using event that fires AFTER the key is typed如何使用在键入键后触发的事件使用 jquery 获取按下的键
【发布时间】:2016-08-04 04:49:13
【问题描述】:

是否有替代 onkeypress 触发 AFTER 键被按下.. 我想得到按下的键,但 onkeypress 在键入键之前触发

【问题讨论】:

  • 在按键被按下之前怎么能触发? o_0 我猜你想要keyup 而不是keypress
  • 哦,我的意思是“打字”......我会编辑它

标签: jquery keyboard


【解决方案1】:

我认为您正在寻找 keyup 事件。您可以通过以下链接了解更多信息:https://api.jquery.com/keyup/

来自 W3 学校的示例:

$("input").keyup(function(){
    $("input").css("background-color", "pink");
});

在这里找到:http://www.w3schools.com/jquery/event_keyup.asp

另一种方法是

$(document).on('keyup' , '#yourElement' , function(){
 // Do stuff here
});

【讨论】:

    【解决方案2】:

    或者这就是你要找的东西?当您松开按键时,keyup 功能会触发。

    $(document).ready(function() {
      $('input').keyup(function(e) {
        $('lable').text(e.keyCode);
      });
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
    Type in the input:
    <input type="text"><br/>
    Code of the pressed key: <lable></lable>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-13
      • 1970-01-01
      • 2011-03-05
      • 2010-10-24
      • 2012-04-25
      • 1970-01-01
      相关资源
      最近更新 更多