How can I get jquery .val() AFTER keypress event?

后端 未结 6 1735
北荒
北荒 2020-11-28 06:32

I got:

$(someTextInputField).keypress(function() {
  alert($(this).val());
});

Now the alert always returns the value BEFORE the keypress (

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 07:16

    Change keypress to keyup:

    $(someTextInputField).on("keyup", function() {
      alert($(this).val());
    });
    

    keypress is fired when the key is pressed down, keyup is fired when the key is released.

提交回复
热议问题