jQuery UI Autocomplete DownArrow UpArrow

[亡魂溺海] 提交于 2019-12-20 10:23:58

问题


I am having some issues with jQuery Autocomplete and moving DownArrow and UpArrow ?

The problem seems to be that

<input id="autocomplete-input" value="">

focus: function (event, ui) {
       $('#autocomplete-input').val(ui.item.label);
 }

This works great for MOUSE focus - but when I use arrowUp and arrowDown - it selects the ui.item.id over and above the ui.item.label

How can I fix this so that either:

  1. the input val isn't changed at all [i.e. it keeps the users inputted term]
  2. it updates the input val with the focused val the user is on with keydown/keyup

thanks


回答1:


Make sure to prevent the default behavior of the focus event:

focus: function (event, ui) {
    this.value = ui.item.label;
      // or $('#autocomplete-input').val(ui.item.label);

    // Prevent the default focus behavior.
    event.preventDefault();
      // or return false;
}


来源:https://stackoverflow.com/questions/8045773/jquery-ui-autocomplete-downarrow-uparrow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!