Php 如何在空的jquery自动完成字段上调用事件?

Php 如何在空的jquery自动完成字段上调用事件?,php,jquery,autocomplete,Php,Jquery,Autocomplete,我正在使用旧版,如果我的搜索框被清除,我想触发一个事件。这是我目前的代码: jQuery(function($){ $("#searchbox").Watermark("Search"); }); $("#searchbox").autocomplete("search_names.php", { width: 250, selectFirst: false }); $("#searchbox").result(function(event, data, forma

我正在使用旧版,如果我的搜索框被清除,我想触发一个事件。这是我目前的代码:

jQuery(function($){
    $("#searchbox").Watermark("Search");
});


$("#searchbox").autocomplete("search_names.php", {
    width: 250,
    selectFirst: false
});

$("#searchbox").result(function(event, data, formatted) {
    if (data) {
        filterView( data );
    }
});
我已尝试使用结果触发器,但它期望得到有效的结果。知道搜索框为空时如何触发事件吗?基本上我想先恢复搜索结果,再恢复过滤结果


谢谢

一个可能的解决方案可能是使用.focus运行while循环,当用户在搜索框中单击时检查空白字段,并在用户离开搜索框时使用.blur关闭while循环。我还没有试过这个,所以请让我知道它是否有效。真诚地, 凯文

$("#searchbox").focus(function () {
    var checkNull = true;

    while (checkNull == true){
        if (!data) {
            if (previous results are not displayed) {
                your code here to display prior results;
            }
        }
    } 
}


$("#searchbox").blur(function () {
    checkNull = false;
}