我是一个用js编码的新手,我只有一个简单的html自学知识。任何帮助都将不胜感激,谢谢。
这是一个具有自动补全功能的搜索框的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>发布于 2020-02-16 00:20:28
检查代码片段,这将重定向到附加到自动完成数组的链接。在这里,autocomplete数组有带值和url的对象,页面将被重定向到基于所选值的适当url。为了进行测试,所有的值都设置为google。:)
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)
}
});
} );<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>
发布于 2020-02-16 00:14:01
我认为你需要这个:
<!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>https://stackoverflow.com/questions/60239889
复制相似问题