jQuery自动完成取消焦点事件 [英] jquery autocomplete canceling focus event

查看:123
本文介绍了jQuery自动完成取消焦点事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自动完成功能,但是当我输入文本进行搜索并将鼠标移到自动完成功能的结果上时,自动完成功能中的文本会更改为上一个(删除).有谁知道如何改善这种行为.

I have an autocomplete, but when I type text to search and move my mouse over autocomplete's results, text in autocomplete changes to previous(removes). Does anyone know how to improve this behaviour.

我在jQuery.com中阅读

I read in jQuery.com

焦点类型:自动完成焦点

focus Type: autocompletefocus

在将焦点移到某个项目(未选择)之前,ui.item指的是 重点项目.焦点的默认操作是替换文本 字段的值与关注项的值,尽管仅当 焦点事件是由键盘交互触发的.取消这个 事件会阻止值的更新,但不会阻止 菜单项无法集中.

Before focus is moved to an item (not selecting), ui.item refers to the focused item. The default action of focus is to replace the text field's value with the value of the focused item, though only if the focus event was triggered by a keyboard interaction. Canceling this event prevents the value from being updated, but does not prevent the menu item from being focused.

但是我不知道如何取消焦点事件.

but I don't know how to cancel focus event.

推荐答案

您是对的,jQuery autocpmplete在自己的[演示页面] [1]上有该错误.
如果您键入一些文本并且自动完成显示了一些答案,则可以得到它.然后添加一些其他文本,同时将鼠标悬停在一个答案上,程序将剪切您的其他文本.
您可以在自动填充小部件中检查源代码

You're right, jquery autocpmplete has that bug on they own [demo page][1].
You can get it if you typed some text and autocomplete had showed some answers; then you adding some additional text and at the same time you are hovering on one of the answer the programm will cut your additional text.
You can check source code in autocomplete widget

blur: function (event, ui) {
           // don't set the value of the text field if it's already correct
           // this prevents moving the cursor unnecessarily
           if (self.menu.element.is(":visible") && (self.element.val() !== self.term)){
               self.element.val(self.term);
           }
       }

您可以通过注释此行self.element.val(self.term);来解决您的问题 但这不是一个好主意.您可以将错误发布到jquery!

And you can figure out you problem by commenting out this line self.element.val(self.term); But this is not realy good idea. You can post a bug to jquery!

这篇关于jQuery自动完成取消焦点事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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