【问题标题】:autocomplete.js not working properly and not populating other fieldsautocomplete.js 无法正常工作且未填充其他字段
【发布时间】:2021-06-11 21:27:34
【问题描述】:

我正在尝试通过姓名获取电子邮件和电话。姓名即将到来,但在选择时电子邮件和电话字段未填充,并且在控制台中我看到错误:

Uncaught TypeError: Cannot read property 'getSelectedItemData' of undefined
    at S.fn.init.a.fn.getSelectedItemData (jquery.easy-autocomplete.min.js:10)
    at Object.onSelectItemEvent (add-invoice.php:276)
    at HTMLDivElement.<anonymous> (jquery.easy-autocomplete.min.js:10)
    at HTMLDivElement.dispatch (jquery-3.5.1.min.js:2)
    at HTMLDivElement.v.handle (jquery-3.5.1.min.js:2)
    at Object.trigger (jquery-3.5.1.min.js:2)
    at HTMLDivElement.<anonymous> (jquery-3.5.1.min.js:2)
    at Function.each (jquery-3.5.1.min.js:2)
    at S.fn.init.each (jquery-3.5.1.min.js:2)
    at S.fn.init.trigger (jquery-3.5.1.min.js:2)

我的代码是:

<script>
var mgrOptions = {
    url: function(phrase) {
        return "dirSearch.php?t=mgr&phrase=" + phrase;
    },
    getValue: "name",
    list: {
        onSelectItemEvent: function() {
            var email = $("#txtCaseName").getSelectedItemData().email;
            var phone = $("#txtCaseName").getSelectedItemData().phone;

            $("#txtCaseEmail").val(email).trigger("change");
            $("#txtCasePhone").val(phone).trigger("change");
        }
    }
};

$("#txtCaseName").easyAutocomplete(mgrOptions);
</script>

我做错了什么???

谢谢。

【问题讨论】:

    标签: jquery autocomplete


    【解决方案1】:

    确保您已下载并添加了必要的文件:

    <!-- JS file -->
    <script src="/easyAutocomplete/jquery.easy-autocomplete.min.js"></script>
        
        
    <link rel="stylesheet" href="/easyAutocomplete/easy-autocomplete.min.css">
        
    <!-- Additional CSS Themes file - not required-->
    <link rel="stylesheet" href="/easyAutocomplete/easy-autocomplete.themes.min.css">
        
    <!-- Using jQuery with a CDN -->
    <script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
    

    如果在引用文件后仍然没有得到任何东西,请检查页面...在 Chrome 中转到网络,然后在过滤器行中选择 Fetch/XHR。开始输入您希望返回的表单字段值,它应该显示您的 php 脚本正在返回的结构。确保它也能正常工作。

    【讨论】:

      猜你喜欢
      • 2022-01-19
      • 2017-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多