在JQuery中使用顺序搜索结果自动完成

在JQuery中使用顺序搜索结果自动完成,jquery,autocomplete,Jquery,Autocomplete,我想要在JQuery中使用顺序搜索而不是子字符串的自动完成功能 下面的函数检查子字符串,但我只需要顺序搜索 var data = [ "Apple", "Orange", "Pineapple", "Strawberry", "Mango" ]; /* jQuery ready function. Specify a function to execute when the DOM is fully loaded. */ $(document).ready(

我想要在JQuery中使用顺序搜索而不是子字符串的自动完成功能

下面的函数检查子字符串,但我只需要顺序搜索

var data = [
  "Apple",
  "Orange",
  "Pineapple",
  "Strawberry",
  "Mango"
    ];


/*  jQuery ready function. Specify a function to execute when the DOM is fully loaded.  */
$(document).ready(

  /* This is the function that will get executed after the DOM is fully loaded */
  function () {

  /* binding the text box with the jQuery Auto complete function. */
    $( "#fruits" ).autocomplete({
      /*Source refers to the list of fruits that are available in the auto complete list. */
      source:data,
      /* auto focus true means, the first item in the auto complete list is selected by default. therefore when the user hits enter,
      it will be loaded in the textbox */
      autoFocus: true ,

    });
  }

);

jQueryUI有这个例子

通过键入
a
将只返回
Apple

var数据=[
“苹果”,
“橙色”,
“菠萝”,
“草莓”,
“芒果”
];
/*jqueryready函数。指定DOM完全加载时要执行的函数*/
$(文件)。准备好了吗(
/*这是DOM完全加载后将执行的函数*/
函数(){
/*使用jQuery自动完成功能绑定文本框*/
$(“#水果”)。自动完成({
来源:功能(请求、响应){
var matcher=newregexp(“^”+$.ui.autocomplete.escapeRegex(request.term),“i”);
响应($.grep(数据、功能(项目)){
返回匹配器测试(项目);
}));
},
/*auto focus true表示自动完成列表中的第一项默认选中。因此,当用户点击enter时,
它将被加载到文本框中*/
自动对焦:对,
});
}
);