焦点仍然在球场上

Focus remains on field

本文关键字:焦点      更新时间:2023-09-26

我想弄清楚为什么我的焦点仍然在一个元素上。这是我使用的自动完成插件中的html:

<autocomplete id="search" ng-model="query" attr-placeholder="" click-activation="true" data="items" on-type="updateItems" on-select="searchItems"></autocomplete>

但是每次我按enter键时,无论我是否将焦点放在输入字段上,或者甚至在其他字段上,每次都会调用on-select函数

这个东西是在插件本身,也许它需要一些改变?

document.addEventListener("blur", function (e) {
    // disable suggestions on blur
    // we do a timeout to prevent hiding it before a click event is registered
    setTimeout(function () {
        scope.select();
        scope.setIndex(-1);
        scope.$apply();
    }, 150);
}, true);

您可以使用下面的代码来监视最后选择的输入字段:

var lastFocusedElement = '';
// This would catch any input field - so you could add your forms selector too.
// for example : $("#myForm:input")
$(":input").focus(function () {
     lastFocusedElement = $(this);
});
然后使用animate: 中的完整回调函数:
$("#div_NotificationOuter").animate({ bottom: '+=30px' }, 4000,function(){
  if (lastFocusedElement != ''){
    lastFocusedElement.trigger('focus');
  }
});