关闭引导程序模式后删除现有的内容/数据 [英] Delete the existing content/data when bootstrap modal is closed

查看:76
本文介绍了关闭引导程序模式后删除现有的内容/数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用bootstrap 3模式来生成确认对话框,然后再删除帖子.当前我正在做的是从删除链接中获取href值,并在单击delete(confirm)时显示它.稍后,我将使用该链接将ajax请求发送到服务器. 这是简化的代码.

Hi I am using bootstrap 3 modal to generate confirm dialog box before someone deletes a post. Currently what I am doing is grab the href values from the delete link and display it when delete(confirm) is clicked. I will use that link to send ajax request to server later. Here is the simplified code.

// 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值).

However, when the dialog box is closed and opened second time it remembers the content(href values) from first click event.

推荐答案

解决方案是在关闭引导模态窗口后将其完全破坏,而在再次打开该窗口时不还原所有内容.

The solution is to destroy the bootstrap modal window completely after closing it , to not restore everything when open it again .

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

});

如果是引导程序3,则可以使用:

if is bootstrap 3 you can use:

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

这篇关于关闭引导程序模式后删除现有的内容/数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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