首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何向搜索建议添加链接?

如何向搜索建议添加链接?
EN

Stack Overflow用户
提问于 2020-02-15 22:51:03
回答 2查看 432关注 0票数 3

我是一个用js编码的新手,我只有一个简单的html自学知识。任何帮助都将不胜感激,谢谢。

这是一个具有自动补全功能的搜索框的javascript。我在问如何为每个变量添加链接。

代码语言:javascript
复制
<script>
$(document).ready(function(){
    $('input.autocomplete').autocomplete({
        data: {
            "Single Seats": null,
            "Multiple Seats": null,
            "Beds": null,
            "Entertainment": null,
            "Tables": null,
            "Storage": null,
            "Sets": null,
            "Other": null
        }
    });
});
</script>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-02-16 00:20:28

检查代码片段,这将重定向到附加到自动完成数组的链接。在这里,autocomplete数组有带值和url的对象,页面将被重定向到基于所选值的适当url。为了进行测试,所有的值都设置为google。:)

代码语言:javascript
复制
var $ = jQuery;
$( function() {
    var availableTags = [
      {value:"ActionScript", link:'https://google.com'},
      {value:"AppleScript",link:'https://google.com'},
      {value:"Asp",link:'https://google.com'},
      {value:"BASIC",link:'https://google.com'},
      {value:"C",link:'https://google.com'},
      {value:"C++",link:'https://google.com'},
      {value:"Clojure",link:'https://google.com'},
      {value:"COBOL",link:'https://google.com'},
      {value:"ColdFusion",link:'https://google.com'},
      {value:"Erlang",link:'https://google.com'},
      {value:"Fortran",link:'https://google.com'},
      {value:"Groovy",link:'https://google.com'},
      {value:"Haskell",link:'https://google.com'},
      {value:"Java",link:'https://google.com'},
      {value:"JavaScript",link:'https://google.com'},
      {value:"Lisp",link:'https://google.com'},
     
    ];
    $( "#tags" ).autocomplete({
      source: availableTags,
      select: function( event, ui ) {
        console.log(ui.item.link);
        window.location.replace(ui.item.link)
      }
    });
  } );
代码语言:javascript
复制
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Autocomplete - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  
  </script>
</head>
<body>
 
<div class="ui-widget">
  <label for="tags">Tags: </label>
  <input id="tags">
</div>
 
 
</body>
</html>

票数 2
EN

Stack Overflow用户

发布于 2020-02-16 00:14:01

我认为你需要这个:

代码语言:javascript
复制
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Autocomplete - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    var availableTags = [
      "ActionScript",
      "AppleScript",
      "Asp",
      "COBOL",
      "ColdFusion",
      "Erlang",
      "Fortran",
      "Ruby",
      "Scala",
      "Scheme"
    ];
    $( "#tags" ).autocomplete({
      source: availableTags
    });
  } );
  </script>
</head>
<body>

<div class="ui-widget">
  <label for="tags">Tags: </label>
  <input id="tags">
</div>


</body>
</html>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60239889

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档