我在Django项目中不断遇到此错误,并且我实际上尝试了我在Stackoverflow上找到的一切,但没有任何作用
错误:未捕获的类型错误:$(...).autocomplete不是
包含在base.html中的函数:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
自动完成代码参考: https://www.geeksforgeeks.org/implement -search-autocomplete-for-input-fields-in-django/
编辑: 它被用在一个模板中,其中我只有一个字段,并且我必须使用自动完成功能显示电子邮件。该模板扩展了base.html
{% block custom_js %}
<script type="text/javascript">
$( function() {
var _emails = "{{ emails }}".split(',');
var availableTags = [];
$.each(_emails, function(index, value){
availableTags.push(value);
});
$( "#id_email" ).autocomplete({
source: availableTags
});
});
</script>
{% endblock custom_js %}
Error: Uncaught TypeError: $(...).autocomplete is not a function
included in base.html:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
autocomplete code reference:
https://www.geeksforgeeks.org/implement-search-autocomplete-for-input-fields-in-django/
EDIT:
its being used in a template where I have only one field and I have to show emails using the autocomplete feature. The template extends base.html
{% block custom_js %}
<script type="text/javascript">
$( function() {
var _emails = "{{ emails }}".split(',');
var availableTags = [];
$.each(_emails, function(index, value){
availableTags.push(value);
});
$( "#id_email" ).autocomplete({
source: availableTags
});
});
</script>
{% endblock custom_js %}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案以备将来参考:
我尝试了此问题,它对我有用。
https://forum.jquery.com/topic/ 被群体型型式catcomplete-is-is-not-a功能
如论坛的答案中所建议的,更改函数($) 。我还没有在其他地方包含jQuery,但此错误尚未解决。
Solution for future reference:
I tried this and it worked for me.
https://forum.jquery.com/topic/uncaught-typeerror-catcomplete-is-not-a-function
Changed function() to function($) as suggested in the answer in the forum. I haven't included jquery elsewhere yet this error wasn't resolving.