jQuery的自动完成 - 鼠标下方的文本框中选择会导致显示菜单后, [英] jquery autocomplete - mouse below text box a causes selection after menu is shown

查看:122
本文介绍了jQuery的自动完成 - 鼠标下方的文本框中选择会导致显示菜单后,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在页面顶部的一个jQuery自动完成文本框。通常情况下,用户将在文本框中单击以使其获得焦点,移动鼠标了,然后开始打字。如果用户移动自动完成下面的鼠标,他们的鼠标位置可以在不经意间选择一个建议,即使他们没有做任何事情。发生这种情况时,用户点击回车键,自动完成使用他们意外的选择。

I have a jquery autocomplete text box at the top of a page. Typically, a user will click in the text box to give it focus, move the mouse away, and then start typing. If the user moves the mouse below the autocomplete, their mouse location can inadvertently select a suggestion, even though they didn't do anything. When this happens and the user hits the enter key, the autocomplete uses their inadvertent selection.

这是一个重大的问题,因为我的自动完成的位置......这一切发生的时候,是非常令人沮丧的我的用户。我需要一个解决方案,但我似乎无法得到自动完成第一把钥匙给我preSS事件。

This is a major problem due to the location of my autocomplete... it happens all the time, and is extremely frustrating to my users. I need a solution, but I can't seem to get the autocomplete to give me the keypress event first.

下面是我的例子:

http://jsfiddle.net/uqTv9/2/

推荐答案

只要您可以使用select事件为prevent进入这样的:

Simply you can use select event to prevent enter like this :

$('#query').autocomplete({
    source: [
        "A",
        "AAA",
        "AAAAA",
        "AAAAAAAAA",
        "AAAAAAAAA",
        "AAAAAAAAAAA",
        "AAAAAAAAAAAAAA",
        "AAAAAAAAAAAAAAAA",
        "AAAAAAAAAAAAAAAAAA",
        "AAAAAAAAAAAAAAAAAAAAA",
        "AAAAAAAAAAAAAAAAAAAAAAAA"
    ],
    select: function(e, ui) {
        if(e.which === 13 ) {  return false; }
    }
});

的jsfiddle: http://jsfiddle.net/gurkavcu/xSKPz/1/

这篇关于jQuery的自动完成 - 鼠标下方的文本框中选择会导致显示菜单后,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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