getting the value of a form field after keypress event

前端 未结 2 436
小鲜肉
小鲜肉 2021-01-11 10:46

myInput.value is one keystroke behind when I examine it in a keyPress event handler. So if the users types \"a\", myInput.value gives me \"\". Then when the user types \"b\"

相关标签:
2条回答
  • 2021-01-11 11:42

    Use the keyUp event, it should definitely give you the value you are looking for.

    0 讨论(0)
  • 2021-01-11 11:42

    When I had this problem, the thing I actually wanted was the oninput event handler.

    One notable difference between this and the keyUp solution is that if you e.g. hold down a key to repeat it, oninput will get called every time the key repeats, but keyUp will only get called when the key is released.

    0 讨论(0)
提交回复
热议问题