gpt4 book ai didi

javascript - Jquery 自动完成不是一个函数

转载 作者:行者123 更新时间:2023-11-28 15:17:28 25 4
gpt4 key购买 nike

我正在尝试将 JQuery 的自动完成功能实现到网站上的输入字段中。检查员给我一个错误,内容是:

“未捕获的类型错误:$(...).autocomplete 不是一个函数”。

我相信问题可能与我的脚本标签的顺序有关,但到目前为止我尝试过的所有方法都不起作用。这是我的内容:

<head>
<title></title>
<link href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" rel="Stylesheet">
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
</head>
<body>
<script type="text/javascript">
var schools = new Array();
$(document).ready(function () {

$("#school").autocomplete ({
minLength: 2,
source: schools,
select: function (e, ui) {
e.target.value = ui.item.label;
$("#schoolValue").val(ui.item.value);
e.preventDefault();
}
});
</script>
</body>

最佳答案

您尚未使用 school id 定义任何元素。检查下面的工作代码以与您自己的代码进行比较。

var schools = ['abc', 'xyz'];
$(document).ready(function() {

$("#school").autocomplete({
minLength: 2,
source: schools,
select: function(e, ui) {
e.target.value = ui.item.label;
$("#schoolValue").val(ui.item.value);
e.preventDefault();
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<head>
<title></title>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
</head>

<body>
<label for="school">Tags:</label>
<input id="school">
</body>

关于javascript - Jquery 自动完成不是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33044237/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com