Twitter Bootstrap:关闭下拉列表时调用js函数 [英] Twitter Bootstrap: Call a js function when a dropdown is closed

查看:65
本文介绍了Twitter Bootstrap:关闭下拉列表时调用js函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当关闭或切换引导下拉列表时,是否存在可以触发的事件?

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

推荐答案

In最后,我发现唯一可靠的方法是使用jquery的数据api来存储下拉列表的状态,并将click事件添加到按钮和文档中。

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();
        }
    });

});

这篇关于Twitter Bootstrap:关闭下拉列表时调用js函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆