[英]jQuery UI Autocomplete autoFocus not bound to mouse out
I've tried to read around on this today, and I can't find an answer here nor via Google. 我今天尝试阅读有关此内容的信息,但无法在此处找到答案,也无法通过Google找到答案。 I'm hoping someone can help say "you idiot, this is the way to do it" and I can move on with my life.
我希望有人可以帮忙说“你这个白痴,这是做到这一点的方式”,我可以继续我的生活。 :)
:)
I have jquery UI autocomplete
plugin installed and working fine. 我已经安装了
jquery UI autocomplete
插件,并且工作正常。 I added autoFocus: true
and I can now tab out and it will select the first option that was available. 我添加了
autoFocus: true
,现在可以跳出,它将选择第一个可用的选项。 However, if I focusout
on the input element, the autocomplete does not force a selection by choosing the first option. 但是,如果我将
focusout
集中在输入元素上,则自动完成功能不会通过选择第一个选项来强制选择。 I have tried many different, horrible, ways to force this to occur, and I have done it, but it lags my system out and crashes the page. 我尝试了很多不同的方法来迫使这种情况发生,但是我已经做到了,但是它使我的系统落后并导致页面崩溃。
I have jQuery v1.10.2
, jQuery UI Core 1.9.1
, and jquery UI Autocomplete 1.10.4
running with my application now. 我有
jQuery v1.10.2
, jQuery UI Core 1.9.1
,以及jquery UI Autocomplete 1.10.4
我的申请现在正在运行。
Current autocomplete event: 当前的自动完成事件:
$("#element").autocomplete({
source: "search.php",
minLength: 2,
select: function(event, ui) {
$('#element').val(ui.item.value);
getOptions();
},
autoFocus: true,
html: false,
open: function(event, ui) {
$(".ui-autocomplete").css("z-index", 1000);
}
});
This works correctly but lags my page out and will crash the browser. 这可以正常工作,但会使我的页面滞后,并使浏览器崩溃。 There's some form of infinite loop here that I can see but can't seem to understand in order to fix:
我可以看到某种形式的无限循环,但似乎无法理解以进行修复:
$("#element").click(function() {
$("#element").blur(function() {
$('.ui-autocomplete .ui-menu-item:first-child').click();
$("#quantity").focus();
});
});
Thanks again for any help. 再次感谢任何帮助。 I sure hope it's a "DOH! Here's the issue."
我肯定希望它是“ DOH!这是问题所在”。 sort of problem and I just needed a new set of fresh eyes.
有点问题,我只需要换一组新的眼睛即可。 :)
:)
Welp, I gave it about an hour and only got six views. 韦尔普,我花了一个小时左右,只有六次观看。 I was able to get something working.
我能够使一些工作。 Will it work out in all browsers?
可以在所有浏览器中使用吗? Only time and, most likely, many hours of frustration will tell.
只有时间,而且很可能是许多小时的挫败感才会说明一切。
$("#element").autocomplete({
source: "search.php",
minLength: 2,
select: function(event, ui) {
$('#element').val(ui.item.value);
getOptions();
},
autoFocus: true,
mustMatch: true,
html: false,
open: function(event, ui) {
$(".ui-autocomplete").css("z-index", 1000);
}
}).blur(function() {
if($('#element').val() != $('#element').data('selected-item')) {
if($('.ui-autocomplete').length) {
$('.ui-autocomplete .ui-menu-item:first-child').click();
$('#quantity').focus();
}
}
});
I used blur
to get the event of losing focus on the input field. 我使用
blur
来获得失去对输入字段焦点的事件。 If the value of the input field doesn't equal the previously selected value, then I check to make sure the ui-autocomplete
element exists. 如果输入字段的值不等于先前选择的值,那么我检查以确保
ui-autocomplete
元素存在。 If it does, then I force a click event on the first child of the ui-menu-item
element, which is the list of results. 如果是这样,那么我会在
ui-menu-item
元素的第一个子元素(即结果列表)上强制执行click事件。 My concern is with the first-child selector and some cross browser issues, and I believe my first test in IE wasn't that great. 我关心的是第一个孩子选择器和一些跨浏览器问题,我相信我在IE中的第一个测试不是很好。 But, for Chrome/FF/Safari?
但是,对于Chrome / FF / Safari? It works perfectly!
它完美地工作!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.