关闭bootstrap模式时删除现有内容/数据

时间:2014-11-30 09:50:12

标签: jquery twitter-bootstrap

您好我正在使用bootstrap 3模式生成确认对话框,然后才会有人删除帖子。目前我正在做的是从删除链接中获取href值,并在单击删除(确认)时显示它。我将使用该链接稍后向服务器发送ajax请求。 这是简化的代码。

// when modals shown
$('#confirm-delete').on('shown.bs.modal', function(e) {
    var url = $(e.relatedTarget).data('href');

    $('button.delete').click(function(){
        alert(url);
    });
});

// when modals closed
$('#confirm-delete').on('hidden.bs.modal', function(e) {
   $(this).removeData('bs.modal');
});  

但是,当对话框关闭并第二次打开时,它会记住第一次点击事件中的内容(href值)。

1 个答案:

答案 0 :(得分:0)

解决方案是在关闭后完全销毁引导模态窗口,以便在再次打开时不恢复所有内容。

$('#modal').on('hidden', function(){
$(this).data('modal', null);

});

如果是bootstrap 3,你可以使用:

$("#modal").on('hidden.bs.modal', function () {
    $(this).data('bs.modal', null);
});