OnChange 事件无法正常工作
我的 OnChange 事件无法正常工作 - 我想当用户更改文本框的值时触发函数。但在我的测试中,我发现当文本框的值发生变化并且文本框失去焦点时,该函数就会触发。我的浏览器有问题吗?还是与JavaScript的能力有关?如果最后一个是真的我该怎么办?提前致谢。
My OnChange event does not work properly - I want to trigger a function when user changes a textbox's value. But in my tests I have seen that the function triggers when textbox's value changes and textbox loses focus. Something wrong with my browser? Or is it about the ability of JavaScript? If the last one is true how can I can do that? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当输入字段失去焦点或从下拉菜单中选择一个选项时,
onchange
事件将触发,这是正常行为。如果您希望当用户在输入字段中键入时触发一个事件,您可以使用 onkeypress< /a>、onkeydown 或 onkeyup 事件。
onchange
event will trigger when an input field loses focus or when an option is selected from a dropdown menu, that's normal behavior.If you want an event that will be triggered as the user types in an input field, you can use onkeypress, onkeydown or onkeyup events.
你可以用 jquery 来做:
You could do with jquery:
还要在 keyup 事件和模糊事件上编写 jquery 代码,因为如果用户仅使用鼠标将一些复制的数据粘贴到文本框中,在这种情况下,只有 jquery 调用模糊事件。
write the jquery code on keyup event and blur event also, because if user paste some copied data into textbox by using mouse only in that case only blur event called by jquery.