简体   繁体   English

jQuery UI自动完成小部件消失

[英]JQuery UI Autocomplete widget disappear

ODD behaviour from my Autocomplete. 我的自动完成功能中存在奇数行为。 It all works fine but the result display is all messed up: 一切正常,但结果显示混乱了:

  • if I press one key it will display the results just fine right below my searchBar using the widget; 如果我按一个键,它将使用小部件在我的searchBar下方恰好显示结果;

  • at the moment I press the second letter in my searchbar the widget disappears and the results are being displayed in my #body 目前,我在搜索栏中按了第二个字母,小部件消失了,结果显示在#body中

I tried using of: "#searchBar", but it does not seem to fix the issue; 我尝试使用of: "#searchBar",但似乎无法解决问题; I would like to keep the widget at all times. 我想一直保留小部件。

here is my code: 这是我的代码:

$($("#searchBar").keyup(function() {
var querySearch = $("#searchBar").val();

$("#searchBar").autocomplete({

    source: function(request, response) {
        $.ajax({
            url: "php/queryDB.php",
            type: 'post',
            dataType: "json",
            of: "#searchBar",
            data: {
                action: 'autoComplete',
                parameter: querySearch
              },
            success: function(data) {
              response(data);
              }
            });
        }});
}));

I have the following code generated by autocomplete in my console: <input id="searchBar" type="text" name="SearchTextField" placeholder="Search" autocomplete="off" class="ui-autocomplete-input"> 我在控制台中通过自动完成功能生成了以下代码: <input id="searchBar" type="text" name="SearchTextField" placeholder="Search" autocomplete="off" class="ui-autocomplete-input">

Turns out I had two issues: 原来我有两个问题:

safari was fooling me with its autocomplete so I was thinking it was the Jquery widget (first time using the Jquery method so that's why I did not realise) and I did not format my code properly Safari的自动完成功能在骗我,所以我认为它是Jquery小部件(第一次使用Jquery方法,这就是为什么我没有意识到)并且我没有正确格式化我的代码

For info here is the final code that worked for me: 有关信息,这是对我有用的最终代码:

$("#searchBar").autocomplete({
    delay: 500,
    minLength: 2,
    appendTo: "#autocompleteResultsDiv",
    autoFocus: true,
    classes: {
              "ui-autocomplete": "highlight"
              },
    position: { my : "right top", at: "right bottom" },

   source: function(request, response) {

$.ajax({
    url: "DB.php",
    type: 'post',
    dataType: "json",
    cache: false,
    data: {
        action: 'autoComplete',
        parameter: $("#searchBar").val()
      },
    success: function(data) {
      response(data);
    }
  });
}
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM