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

前端 未结 6 1377
执念已碎
执念已碎 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:42

    There isn't a documented event, but you can use the .open class of the .dropdown and the jQuery click() event:

    $('#the-dropdown').click(function () {
        if($(this).hasClass('open')) {
            alert('it works');
        }
    });
    

    For toggling, use just the click() event.

    Here is the jsfiddle.

提交回复
热议问题