在按下按键事件后获取表单字段的值

在按下按键事件后获取表单字段的值

问题描述:

myInput.value是一个键击。因此,如果用户输入a,myInput.value会给我。然后,当用户键入b时,myInput.value会给我a,等等。通过触发事件的击键输入的字符似乎不会更新该值。我究竟做错了什么?
谢谢
-Morgan

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", myInput.value gives me "a", and so it. The value doesn't seem to get updated with the character input by the keystroke that triggered the event. What am I doing wrong? thanks -Morgan

使用keyUp事件,它肯定会给你你的价值寻找。

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