OnChange 事件无法正常工作

发布于 2024-12-18 00:34:10 字数 171 浏览 4 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

终难遇 2024-12-25 00:34:11

当输入字段失去焦点或从下拉菜单中选择一个选项时,onchange 事件将触发,这是正常行为。

如果您希望当用户在输入字段中键入时触发一个事件,您可以使用 onkeypress< /a>、onkeydownonkeyup 事件。

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.

相思碎 2024-12-25 00:34:11

你可以用 jquery 来做:

$("textbox_id").keyup(function(){
   //do something here
});

You could do with jquery:

$("textbox_id").keyup(function(){
   //do something here
});
洋洋洒洒 2024-12-25 00:34:11

还要在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文