how to make the dropdown autocomplete to disappear onblur or click outside in jquery?

后端 未结 2 1893
深忆病人
深忆病人 2021-01-20 16:17

Below is the function which is called to show the autocomplete in a search box...I want the auto complete to disappear onBlur or click outside the search box...please tell m

相关标签:
2条回答
  • 2021-01-20 16:56

    This is a bit simpler:

    $('body').click( function() {
        $('.ui-autocomplete').hide('');
    
    });
    
    0 讨论(0)
  • 2021-01-20 17:02

    You could try binding the click event to the document. Something like this:

    $(document).bind('click', function (event) {
        // Check if we have not clicked on the search box
        if (!($(event.target).parents().andSelf().is('.searcher'))) {
            // Hide/collapse your search box, autocomplete or whatever you need to do
        }
    });
    
    0 讨论(0)
提交回复
热议问题