jQuery自动完成鼠标选项会触发模糊事件 [英] jQuery autocomplete mouse choice fires the blur event

查看:69
本文介绍了jQuery自动完成鼠标选项会触发模糊事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jQuery UI .autocomplete(),我真的很喜欢。我确实有一个我无法解决的主要问题。

I use the jQuery UI .autocomplete(), which I really love. I do have one major problem I cannot solve.

当我输入一个字母时,请说 s stackoverflow 出现在下拉菜单中,我使用鼠标选择 stackoverflow ,然后输入框暂时失去焦点,这会导致 onblur 事件被调用。

When I type a letter, say s, and stackoverflow appears in the drop-down menu, and I use the mouse to select stackoverflow, then the input box temporarily loses focus, which causes the onblur event to be called.

虽然技术上输入框是模糊,但是当我点击时,这违背了可用性直觉。如何修复这种恼人的行为?

Although technically the input box is blured when I click, this goes against usability intuition. How can I fix this annoying behavior?

推荐答案

您可以尝试使用jQuery UI自动完成的打开和关闭事件来控制文本框的模糊事件。打开自动填充功能后,您可以禁用模糊事件,当它关闭时,您可以再次启用模糊事件。我在 jsfiddle.net 上设置了一个工作示例。希望它有所帮助。

you can try using the jQuery UI autocomplete's open and close event to control your textbox's blur event. When the autocomplete is open you disable the blur event and when it close you enable your blur event again. I have setup a working example at jsfiddle.net. Hope it helps.

var disable=false;

$( "#tags" ).autocomplete({
  source: availableTags,
  open: function(event, ui) { disable=true },
  close: function(event, ui) {
    disable=false; $(this).focus();
  }
}).blur(function() {
  if(!disable) {
    alert('blur');
  }
});

这篇关于jQuery自动完成鼠标选项会触发模糊事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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