我使用typeahead.js作为自动完成文本框 .

当我输入并从建议,文本框和隐藏字段中选择一个值时,正确设置值 . 但是当我在没有选择文本框值的情况下输入文本框的值和松散焦点时,隐藏字段值不匹配 .

如果未从建议中选择输入值,如何清除文本框和隐藏字段的值 .

我的代码如下

$(function () {
        $('#txtCustomer').typeahead({
            hint: true,
            highlight: true,
            minLength: 1,
            source: function (request, response) {
                $.ajax({
                    url: '/Customer.aspx/GetCustomers',
                data: "{ 'prefix': '" + request + "'}",
                dataType: "json",
                type: "POST",
                contentType: "application/json; charset=utf-8",
                success: function (data) {
                    items = []; map = {};
                    var obj = JSON.parse(data.d);
                    $.each(obj.Data, function (i, value) {
                        map[name] = { id: value.CustomerID, name: value.FullName };
                        items.push(map[name]);
                    });
                    response(items);
                },
                error: OnError,
                failure: OnError,
            });
        },
        updater: function (item) {
            $('#hfCustomerId').val(item.id);
            return item;
        }
    });
    });