jQuery keyboard events

后端 未结 4 808
萌比男神i
萌比男神i 2020-11-29 13:31

Using jQuery, I would like to capture a keyboard event that is:

  • before the user lifts their finger from the key
  • after the characters
4条回答
  •  一生所求
    2020-11-29 14:09

    Use keyup event, an example on jsFiddle

    $("textarea").keyup(function(e){
       alert($(this).val());
    });
    

    It happens after you lift the key. I don't know what you want to achieve, but you can store the state before lifting the key (on keydown or keypress) and restoring later if needed. You also can stop the output in the keyup event using e.preventDefault(), so even after the key is up it will not register the values in the area.

提交回复
热议问题