2017-02-25 108 views
0

我正在使用jQuery自动填充小部件,其中用户键入与公司和其他数据相关联的数字,并且该数据填充在其他字段中。目前,用户键入号码,然后必须从列表中选择它来完成其他字段。我的目标是消除用户不必从列表中选择号码,而是键入号码,点击搜索按钮并填充字段。我怎样才能做到这一点?Jquery自动完成 - 自动完成输入

这里是我的代码:

$("#moveinbooth").autocomplete({ 
    source: "/sites/schedule.php", 
    change: function (event, ui) { 

     if (!ui.item) { 
      //http://api.jqueryui.com/autocomplete/#event-change - 
      // The item selected from the menu, if any. Otherwise the property is null 
      //so clear the item for force selection 
      $("#moveinbooth").val(""); 
     } 

    }, 
    minLength: 0, 
    position: { 
     my: "center bottom", 
     at: "center top", 
     collision: "flip" 
    }, 
    scroll: false, 
    select: function (event, ui) { 
     $(this).autocomplete('disable'); 
     $('#exhibitorname').val(ui.item.exhibitor); 
     $('#moveindate').val(ui.item.moveindate); 
     $('#moveintime').val(ui.item.moveintime); 
     $('#moveoutdate').val(ui.item.moveoutdate); 
     $('#moveouttime').val(ui.item.moveouttime); 
    } 

}) 

回答

0

如果他们必须键入它,而不是选择它,然后你还需要自动完成?如果你这样做,你的问题是用户仍然需要在列表中选择它,即使数字完全输入,只需监听选择事件或TAB或ENTER键。