当用户按“Enter”键时自动完成停止
我在商业网站上使用 AutoCompleteExtender。我的问题是用户快速输入单词的一部分并立即按“Enter”键,这会导致自动完成控件不返回建议列表。例如,如果我的数据库中有短语“德克萨斯州,美国”,但用户只需快速键入“德克萨斯州”,然后按 Enter 键,则不会出现下拉列表。
我希望自动完成控件忽略用户已按 Enter 的事实并继续获取建议的数据。 (最终的结果是,当当前没有列表时忽略 Enter,但在有列表时选择一个项目)。
我可以通过转到此 Microsoft ASP.NET 站点的示例部分并快速键入一些字符,然后按“Enter”来模拟这个确切的问题。
请问有人可以告诉我我需要做什么吗?
谢谢,马丁
I am using the AutoCompleteExtender on a commercial site. My problem is the users are quickly typing in part of a word and immediately pressing "Enter" which causes the AutoComplete control to NOT come back with a list of suggestions. For example, if my database has the phrase "Texas, United States" in it but the users just type "Texas" quickly followed by Enter then the dropdown list does not appear.
What I would like is for the AutoComplete control to ignore the fact the user has pressed Enter and go and fetch the suggested data anyway. (The ultimate would be if it ignored Enter when there was currently no list, but selected an item when there was a list).
I can simulate this exact problem by going to the samples section of this Microsoft ASP.NET site and typing in some characters very quickly followed by 'Enter'.
Please could someone tell me what I need to do?
Thanks, Martin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我之前已经解决过这个问题,在作为自动完成目标的文本框上有一个额外的 keydown 处理程序。将下面代码片段中的
this._autoCompleteBehavior
替换为对 AutoCompleteBehavior 实例的引用(可通过$find()
和BehaviorID
获取)。这里的想法是强制自动完成行为认为它需要通过调用_onTimerTick()
来执行查找,该查找在键入延迟到期后执行。默认情况下,通过按 Enter 键可以取消键入延迟,因此这只会强制在 Enter 或 Tab 上进行查找。免责声明:我的 hack 引用了 AjaxControlToolkit 代码的“私有”成员(以下划线开头的内容是“私有”),因此可能不能保证它是面向未来的。
I've hacked around this problem before with an extra keydown handler on the textbox that is the target of the auto-complete. Replace
this._autoCompleteBehavior
in the snippet below with a reference to your instance of AutoCompleteBehavior (obtainable via$find()
and theBehaviorID
). The idea here is to force the auto-complete behavior to think it needs to perform a lookup by calling_onTimerTick()
, which executes after the typing delay has expired. By default the typing delay gets cancelled by hitting the enter key, so this just forces the lookup anyway on enter or tab.Disclaimer: my hack references "private" members of the AjaxControlToolkit code (stuff that starts with underscore is "private"), so it is probably not guaranteed to be future-proof.
嘿,尝试一下 jQuery 或 YUI 自动完成扩展器。它将快如闪电。
Hey try jQuery or YUI autocomplete extender. It will be lightning fast.