Bootstrap模态popover隐藏在关闭

时间:2013-05-01 00:12:33

标签: twitter-bootstrap modal-dialog popover

我有一个模式,在尝试运行时将激活弹出框以进行验证。我在3秒后添加了超时以弹出以隐藏。但是如果关闭模态,超时功能似乎停止,弹出窗口不会隐藏,甚至直接告诉它隐藏也不起作用。

模态HTML

<div class="modal hide fade" id ="password_modal">
    <div class="modal-header">
        <h3>Change Password <span class="extra-title muted"></span></h3>
    </div>
    <div class="modal-body form-horizontal">
        <div class="control-group">
            <label for="current_password" class="control-label">Current Password</label>
            <div class="controls">
                <input type="password" name="current_password">
            </div>
        </div>
        <div class="control-group">
            <label for="new_password" class="control-label">New Password</label>
            <div class="controls">
                <input type="password" name="new_password">
            </div>
        </div>
        <div class="control-group">
            <label for="confirm_password" class="control-label">Confirm Password</label>
            <div class="controls">
                <input type="password" name="confirm_password">
            </div>
        </div>      
    </div>
    <div class="modal-footer">
        <button href="#" class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
        <button href="#" class="btn btn-primary" id="password_modal_save">Save changes</button>
    </div>
</div>

在模态内

options = {
    content: raw_data.errors,
    html: true,
    placement: 'top',
    trigger: 'manual'
}
$('#password_modal_save').popover(options);
$('#password_modal_save').popover('show');
setTimeout(function(){ click.popover('hide'); }, 3000);

模态关闭侦听器

$("body").on("hidden", "#password_modal", function(event){
    $(this).remove(); //Remove the modal to stop duplications
    $('#password_modal_save').popover('hide'); //Targetting the popover directly
    $('.popover').remove(); //Last solution to actually hiding it
});

我希望能有一种更清晰的方法来隐藏$('.popover').remove();

以外的popover

小提琴:http://jsfiddle.net/La2yn/20/

1 个答案:

答案 0 :(得分:1)

使用2.1.0时,有一个bug,当模态关闭时,popover不会隐藏。更新到2.3.1,popover现在也关闭了模态-.-

在以下代码中添加以阻止事件冒泡并关闭模式

$("body").on("hidden", "#password_modal_save", function(e){
    e.stopPropagation(); //Once popover is hidden stop the event from going to parent
});
相关问题