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

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

I got:

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

Now the alert always returns the value BEFORE the keypress (

6条回答
  •  一个人的身影
    2020-11-28 07:35

    Surprised that no one mentioned the js "input" event:

    $(someTextInputField).on('input', function() {
      alert($(this).val());
    });
    

    Recommended.

    https://developer.mozilla.org/en-US/docs/Web/Events/input

提交回复
热议问题