简体   繁体   中英

Jquery autocomplete not firing on keyup unless focus changes

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> 

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");
});
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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