1

我对 jquery 相当陌生并且我正在构建一个 MVC 4 网站,这可以按预期工作,但是我想处理用户清除搜索条件然后我将表更新到其原始状态的事件

    var submitAutoCompleteForm = function (event, ui) {
    var $input = $(this);
    $input.val(ui.item.label);
    var $form = $input.parents("form:first");
    $form.submit();
};
var createAutoComplete = function () {
    var $input = $(this);
    var options = {
        source: $input.attr("data-otf-autocomplete"),
        select: submitAutoCompleteForm
    };
    $input.autocomplete(options);
};
$("input[data-otf-autocomplete]").each(createAutoComplete);
4

2 回答 2

1

您需要添加此选项以要求 0 个字符来激活搜索:

minLength:  0

启用此功能后,您只需点击向下箭头,列表将显示

编辑:

现在我更好地理解了这个问题,您可能需要添加“搜索”选项搜索选项在从源请求任何内容之前触发,因此它是查看该字段是否为空的最佳位置。

,search: function(event, ui){
             if($(this).val() == ''){
                 //code to show table
             }
         }

您也可以使用 change 选项,但根据我的经验,它只会在值发生变化时触发,或者更接近于当字段触发模糊事件时触发,所以我个人并不喜欢它在我的应用程序中的行为

,change: function(event, ui){
             if($(this).val() == ''){
                 //code to show table
             }
         }
于 2013-07-19T14:40:55.650 回答
0

I ended up using a different approach which is essentially the same thing as @MonkeyZeus suggestion

 $("input[type='search']").keyup("search", function () {
    if (!this.value) {
      //code to update the table

} });

于 2013-07-22T19:43:33.247 回答