【问题标题】:How can I close an autocomplete menu after 10 seconds regardless of where the cursor or focus is?无论光标或焦点在哪里,如何在 10 秒后关闭自动完成菜单?
【发布时间】:2020-07-07 15:33:36
【问题描述】:

我有一个 JQuery UI 自动完成功能,希望菜单保持打开状态 10 秒,无论焦点在哪里。我有:

$("#term").autocomplete({
  source: function(request, response) {
    $.ajax({
      url: "https://example.com/",
      dataType: "json",
      data: {
        q: request.term
      },
      success: function(data) {
        response(data);
      }
    });
  },
  close: function() {
    $('.ui-autocomplete').show().delay(10000).hide();
  }  
});

不幸的是,一旦交流区域失去焦点,它就会立即关闭。如果我删除 .delay(10000).hide() 部分,它会无限期地保持打开状态,但我需要在几秒钟后关闭它。谢谢!

【问题讨论】:

  • 你试过使用setTimeout()吗?

标签: javascript jquery jquery-ui jquery-ui-autocomplete


【解决方案1】:
setTimeout(function(){
     $("#term").autocomplete( "disable" );
}, 10000);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多