清空时触发Typeahead.js事件

时间:2017-01-27 15:08:39

标签: javascript jquery typeahead.js

我有Typahead.js plagind并希望在输入字段为空时将data-id属性设置为''。现在我在选择特定建议时使用它来设置data-id,但是当它为空时无法捕获事件。

typeaheadFields.bind('typeahead:select', function (ev, suggestion) {
    $(this).parent().find('.attribute-slider-category-id').attr('data-id', suggestion.id);
});

1 个答案:

答案 0 :(得分:0)

修正了这个问题:

typeaheadFields.keyup(function () {
            if ($(this).val() == '') {
                $(this).parent().find('.attribute-slider-category-id').attr('data-id', '');
            }
        });
相关问题