我在我的 django 项目中不断收到这个错误,我已经尝试了我在 stackoverflow 上找到的所有东西,但没有任何效果
I keep getting this error in my django project and I have literally tried everything I could find on stackoverflow but nothing works
错误: 未捕获类型错误:$(...).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 %}
供以后参考的解决方案:
我试过了,对我有用。
https://forum.jquery.com/topic/uncaught-typeerror-catcomplete-is-not-a-function
已按照论坛答案中的建议将 function() 更改为 function($)。我没有在其他地方包含 jquery,但这个错误没有解决。
错误: 未捕获类型错误:$(...).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 %}
供以后参考的解决方案:
我试过了,对我有用。
https://forum.jquery.com/topic/uncaught-typeerror-catcomplete-is-not-a-function
已按照论坛答案中的建议将 function() 更改为 function($)。我没有在其他地方包含 jquery,但这个错误没有解决。