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 blur
ed 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');
}
});