陷阱回车键,但不能选择浏览器的自动完成建议时, [英] Trap the enter key, but not when choosing the browser's autocomplete suggestion

查看:139
本文介绍了陷阱回车键,但不能选择浏览器的自动完成建议时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面上的文本框的一些,我想,当用户presses其中的任何输入点击链接。

I have some textboxes on a page and I want to click a link when the user presses enter in any of them.

我可以轻松地捕获在 event.key code 寻找13和 event.which ),但我打了一个问题,当在浏览器的自动完成功能踢和建议是什么,用户可能要输入。我们发现用户经常preSS进入接受浏览器的建议,而不是标签。这混淆了用户的链接被点击立即,而他们仍然打算将文本输入到其他一些领域。

I can easily trap the enter button using javascript (by looking for 13 in event.keyCode and event.which), but I hit an issue when the browser's autocomplete feature kicks in and suggests what the user might want to type. We're finding the users often press enter to accept the browser's suggestion, rather than tab. This confuses the users as the link is clicked immediately, whereas they still intended to enter text into some of the other fields.

我知道这将是更好的使用的一种形式和一个提交按钮在这里,但是这是不实际的种种原因。

I know it would be better to use a form and a submit button here, but for various reasons that's not practical.

我使用jQuery,可以随意提供jQuery的解决方案。

I'm using jQuery, so feel free to offer jQuery solutions.

推荐答案

用户总是有preSS向下键,如果他们选择来选择的自动完成文字正确的,为什么当他们一个变量未设置的东西preSS向下键,然后如果他们做的输入preSS事后检查变量。你不应该做链接点击功能,如果变量设置,否则这样做是正常的。

User always have to press the down key if they choose to select one of the auto complete text right, why not set a variable to something when they press the down key, and then if they do the enter press afterwards you check the variable. You should not do the link click function if the variable is set, otherwise do it as normal.

这篇关于陷阱回车键,但不能选择浏览器的自动完成建议时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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