开发者

How to call an event on an empty jquery autocomplete field?

I'm using the legacy jquery autocomplete plugin and would like to开发者_开发问答 trigger an event if my search box is cleared. Here is my current code:

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


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

$("#searchbox").result(function(event, data, formatted) {
    if (data) {
        filterView( data );
    }
});

I've tried using the result trigger but it's expecting a valid result. Any idea how I can trigger an event when the search box is empty? Basically I want to restore the search results prior to the filtered results.

Thanks


a possible solution might be to use the .focus to run a while loop that checks for an empty field when the user is clicked in the search box and close the while loop in using .blur when they leave the searchbox. I haven't tried this, so please let me know if it works. Sincerely, Kevin

$("#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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜