jquery 自动完成在 chrome 中输入键(被劫持?) vs firefox

发布于 2024-10-05 19:44:00 字数 330 浏览 0 评论 0原文

这里有一个情况,我在文本框上使用 jquery 自动完成。我也在监听文本框上的按键事件...这样,当我在文本框中输入时,自动完成会显示建议的文本,如果我不选择建议的文本并按 Enter 键,它应该提交表单,如果我选择建议的文本并按回车键,它会选择建议的值并关闭自动完成框,如果我再次按回车键,它将提交表单。

Firefox 的工作方式就像一个魅力,但在 Chrome 中却不然,似乎自动完成插件正在劫持 Enter 键(键码 13,其他所有键都有效),所以当我单击 Enter 而不选择建议的文本时,什么也没有发生。

以前有人遇到过这个问题吗?解决方法是什么?

提前致谢。

詹姆斯

Got a situation here, I am using jquery autocomplete on a textbox. I am also listening to the keypress event on the textbox... so that when I type in the textbox, autocomplete shows up with suggested text, if I do not select the suggested text and press enter, it should submit the form, if I select a suggested text and hit enter, it selects the suggested value and closes the autocomplete box, if I hit enter again, it will submit the form.

Firefox, works like a charm, but not in Chrome, it seems that autocomplete plugin is hijacking the enter key(keycode 13, every other key works), so when I click on enter without choosing a suggested text, nothing happens.

Has anyone had this issue before? And what's the fix?

Thanks in advance.

James

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

情话难免假 2024-10-12 19:44:00

好的,我看到了一篇关于保持关注输入字段的帖子,这给了我一些解决这个问题的提示。

诀窍是使用“keydown”而不是“keypress”来监听输入事件。

OK, I have come across the post talking about keeping focus on the input field, which gave me some hints on solving this problem.

The trick is to use "keydown" instead of "keypress" to listen to the input event.

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