jQuery UI自动完成:确定搜索窗口是否打开?

mpe*_*pen 12 jquery jquery-ui jquery-ui-autocomplete

我想在输入的onclick事件中触发搜索,但仅当搜索窗口尚未打开时才会触发.目前,我这样做:

$(this).bind('click.ajaxselect', function(e) {
    if(!$(this).autocomplete('widget').is(':visible')) {
        $(this).autocomplete('search','');
    }
});
Run Code Online (Sandbox Code Playgroud)

但我并不是太喜欢使用:visible选择器,因为它也会搜索所有父母.我可以查看一些房产吗?

Dialog有这个isOpen方法,自动完成有类似的东西吗?

Ali*_*guy 19

设置一个简单的变量并不难:

$('.my_selector').bind('autocompleteopen', function(event, ui) {
    $(this).data('is_open',true);
});

$('.my_selector').bind('autocompleteclose', function(event, ui) {
    $(this).data('is_open',false);
});
Run Code Online (Sandbox Code Playgroud)

然后你的听众很容易:

$(this).bind('click.ajaxselect', function(e) {
    if(!$(this).data('is_open')) {
        $(this).autocomplete('search','');
    }
});
Run Code Online (Sandbox Code Playgroud)