jquery - 对象不支持属性或方法 'autocomplete'

标签 jquery

添加一些自动完成代码后出现此错误。在网上搜索后,我确信它与重复的 jQuery 引用有关,但我只引用了一次。

应用程序使用母版页,但相关页面不使用它,因此我在两者中都引用了 jquery。

$(".autosuggest").autocomplete({
  source: function(request, response) {
    $.ajax({
      type: "POST",
      contentType: "application/json; charset=utf-8",
      url: "CustomerTypes.aspx/GetAutoCompleteData",
      data: "{'Customer':'" + document.getElementById('txtCustomerType').value + "'}",
      dataType: "json",
      success: function(data) {
        response(data.d);
      },
      error: function(result) {
        alert("Error");
      }
    });
  }
});

最佳答案

autocomplete()jQueryUI library 中的一个方法。 。您需要添加对该以及 jQuery.js 的引用:

<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.0/themes/smoothness/jquery-ui.css" />
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script>

关于jquery - 对象不支持属性或方法 'autocomplete',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19928826/

相关文章:

javascript - 如何循环访问属于类成员的元素以获取数据并将该数据转换为对象?

javascript - 当事件变为 "true"时,为什么我的 JQuery 函数没有在克隆元素上触发?

javascript - 如何将 dropzone.js 框放入 html 文件中的现有表单中?

jquery - 如何使我的 svg 元素出现?

javascript - Click 事件在触摸设备上触发两次

javascript - jQuery - 按钮的 hasClass 延迟工作

jquery - 移动设备上的 DICOM 图像/视频

javascript - 防止默认功能不起作用

jquery - 验证失败时无法阻止表单提交

javascript - 为什么 chrome 后退/前进按钮不触发 popstate 事件?