除非焦点发生变化,否则 Jquery 自动完成功能不会在键盘上触发

发布于 2024-08-25 22:49:32 字数 536 浏览 3 评论 0原文

我正在使用 jquery 自动完成功能,并且我的文本框有一个 keyup 事件。 当我输入一个字母时,该函数被调用,但该框未填充。

一旦我单击离开该框,然后单击返回该框,自动完成功能就会非常有效。

非常奇怪的问题,我不知道如何解决它。任何帮助将不胜感激。

这是我的代码

$(document).ready(function(){

  var x;
  var output;
  x = document.getElementById('site').value; 

  $.getJSON(url,{field: "name",value: x, comparison: "LIKE"},  
    function(json){    
      //code to format output
      $("#site").autocomplete(output, json);   
  });  
});



<input type ="text" size ="40" id="site"></input> 

I am using a jquery autocomplete and i have a keyup event for my textbox.
When I enter in a letter the function is called but the box is not populated.

Once I click away from the box and then click back into it the autocomplete works great.

Really weird issue and I have no idea how to fix it. Any help would be appreciated.

here's my code

$(document).ready(function(){

  var x;
  var output;
  x = document.getElementById('site').value; 

  $.getJSON(url,{field: "name",value: x, comparison: "LIKE"},  
    function(json){    
      //code to format output
      $("#site").autocomplete(output, json);   
  });  
});



<input type ="text" size ="40" id="site"></input> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清醇 2024-09-01 22:49:32

让我困惑的是插件的文档说

autocomplete(url or data, options)

你的调用不应该像这样吗?这个输出变量到底是什么?

$("#site").autocomplete(json, options)

哪个自动完成?小心提供一个网址。无论如何,您尝试过手动触发焦点吗?

...
function(json){
    //code to format output
    $("#site").autocomplete(output, json).trigger("focus");
});
...

What confuses my is that the documentation of the plugin say

autocomplete(url or data, options)

Shouldn't your call look like this? What is this output variable anyway?

$("#site").autocomplete(json, options)

Which autocomplete? Care to provide an url. Anyway did you try triggering the focus manually?

...
function(json){
    //code to format output
    $("#site").autocomplete(output, json).trigger("focus");
});
...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文