gpt4 book ai didi

jquery - 如何将自动建议添加到我的搜索栏?

转载 作者:行者123 更新时间:2023-12-01 08:40:28 25 4
gpt4 key购买 nike

我正在尝试使用 jquery 将自动建议功能添加到我的搜索栏。但我的尝试没有成功。我已按照教程进行操作,但仍然不明白。

hide().show(2000) 适用于我的搜索栏,但不适用于其他搜索栏。我错过了什么?

编辑:我一直在寻找解决方案,但仍然没有运气。我已经用新的更改编辑了我的代码。我在 https://goodies.pixabay.com/jquery/auto-complete/demo.html 在线找到了该功能它可以在他们的网站上运行。

EDIT2:我已经设法让它作为一个独立的网站工作。是否有可能有什么东西在我的真实网站上阻止了它?如果是这样,我怎样才能覆盖该 block ?

$(function(){
$('#search').autoComplete({
minChars: 2,
source: function(term, suggest){
term = term.toLowerCase();
var choices = ['ActionScript', 'AppleScript', 'Asp', ...];
var matches = [];
for (i=0; i<choices.length; i++)
if (~choices[i].toLowerCase().indexOf(term)) matches.push(choices[i]);
suggest(matches);
}
});
});

我的html代码

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">

<title>Testsite</title>

<script>"jQuery-autoComplete-master/jquery.auto-complete.min.js"</script>
<script>"jQuery-autoComplete-master/jquery.auto-complete.js"</script>
<script>"jQuery-autoComplete-master/jquery.auto-complete.css"</script>

</head>
<body>
<div>
<h1>Search field</h1>
<input id="search" style="width: 500px; height: 50px;font-size:18pt;" placeholder="ActionScript or AppleScript"><br>
<div id="results"></div>
<p></p>


<!--<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>-->
<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 for autocomplete
</script>
</div>

最佳答案

我从两个 jQuery 导入中推断出,您正在寻找来自 jQuery UI 函数的 autocomplete(),而不是 jQuery。

如果是这种情况,您只需要添加他们的 JS,最好还添加他们的 CSS。否则,您需要添加您要使用的 autocomplete() 函数的代码!

您的代码,编辑包括:

$(function() {
var availableTutorials = [
"ActionScript",
"Bootstrap",
"C",
"C++",
];

$('#search').hide(0).show(2000);
$("#search").autocomplete({
source: availableTutorials
});
});
<div>
<h1>Sök efter en bok</h1>
<input id="search" style="width: 500px; height: 50px;font-size:18pt;" placeholder="Titel"><br>
<button id="button" type="button">Sök bok</button>
<div id="results"></div>
<p></p>

<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 src="js/seekBook.js"></script>-->
</div>

Ps:下次,请用英文提供所有内容,并且不要出现无法访问的代码(例如:seekBook.js)。你的问题和我的答案应该适用于每个人,而不仅仅是你的情况;)

关于jquery - 如何将自动建议添加到我的搜索栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48044583/

25 4 0