在按下按键事件后获取表单字段的值 [英] getting the value of a form field after keypress event

查看:95
本文介绍了在按下按键事件后获取表单字段的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

这篇关于在按下按键事件后获取表单字段的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆