Twitter Bootstrap: Call a js function when a dropdown is closed

前端 未结 6 1379
执念已碎
执念已碎 2020-12-13 23:59

Is there an event that I can tie into that is fired when a bootstrap dropdown is closed or toggled?

6条回答
  •  轮回少年
    2020-12-14 00:31

    In the end, the only reliable method that I found was to use jquery's data api to store the state of the dropdown and add click events to the button and the document.

    $(document).ready(function() {
    
        $('#dropdown').data('open', false);
    
        $('#dropdown-button').click(function() {
            if($('#dropdown').data('open')) {
                $('#dropdown').data('open', false);
                update_something();
            } else
                $('#dropdown').data('open', true);
        });
    
        $(document).click(function() {
            if($('#dropdown').data('open')) {
                $('#dropdown').data('open', false);
                update_something();
            }
        });
    
    });
    

提交回复
热议问题