我想 link 使用简单的自动完成 jquery 插入匹配文本

I want to link matching text using easy autocomplete jquery plunging

大家好,我遇到了一个简单的自动完成问题jquery plunging。

我已经在我的网站上成功安装了它,但我遇到了一个简单的问题。 i want link this 我想要 link 使用外部 herf link.When 用户类型并单击此处转到外部。

//Enable description function  
var options = {
    url: "json/linked.json",
    
    getValue: "text",

    template: {
        type: "links",
        type: "description",
        fields: {
            link: "website-link",
            description: "realName"
        }
    },

    theme: "bootstrap"
};

 $("#sheroes").easyAutocomplete(options);  
[
 {
  "text": "Home",
        "realName": "Jahid Hasan",
  "website-link": "http://localhost/test/test.php"
 },
 {
  "text": "Guide",
  "website-link": "http://localhost/test/test.php"
 },
 {
  "text": "Themes",
        "realName": "Bruce Wayne",
  "website-link": "http://localhost/test/test.php"
 },
 {
  "text": "Examples",
  "website-link": "http://localhost/test/test.php"
 },
 {
  "text": "Download",
  "website-link": "http://localhost/test/test.php"
 },
 {
  "text": "Github",
  "website-link": "http://localhost/test/test.php"
 }
]

我该怎么做。 提前致谢

您可以在 JSON 或数据中添加 URL 并通过自动完成与元素绑定,然后像这样调用外部 API 或 link..

$('#scheme').on('autocompleteselect', function (e, ui) 
{  //pass selected value to function    
  doSearch(ui.item.value);
}

重定向到外部的函数link

function doSearch(location) {
    window.location.href = location;
}

只需调用 window.open 方法,当用户更改文本时。

$("#sheroes"). change( function(){ 
  $.getJSON("result.json", function(data){ 
     $.each(data, function(i){
       if(data[i].text==$("#sheroes").val()) {
          window.open(data[i].website_link); 
       } 
     }); 
   }); 
});