我在Django项目中不断遇到此错误,并且我实际上尝试了我在Stackoverflow上找到的一切,但没有任何作用

发布于 2025-01-20 21:15:30 字数 1302 浏览 2 评论 0原文

错误:未捕获的类型错误:$(...).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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

纵性 2025-01-27 21:15:30

解决方案以备将来参考:

我尝试了此问题,它对我有用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文