如何在关闭时完全删除对话框 [英] How to completely remove a dialog on close
问题描述
当ajax操作失败时,我将创建一个带有错误的新div,然后将其显示为对话框.对话框关闭后,我想完全销毁并再次删除div.我怎样才能做到这一点?目前,我的代码如下所示:
When an ajax operation fails, I create a new div with the errors and then show it as a dialog. When the dialog is closed I would like to completely destroy and remove the div again. How can I do this? My code looks something like this at the moment:
$('<div>We failed</div>')
.dialog(
{
title: 'Error',
close: function(event, ui)
{
$(this).destroy().remove();
}
});
当我运行此对话框时,对话框会正确显示,但是当我关闭对话框时,该对话框在html中仍然可见(使用FireBug).我在这里想念什么?我忘记了什么?
When I run this the dialog box shows up correctly, but when I close it the dialog is still visible in the html (using FireBug). What am I missing here? Something I have forgotten?
更新:刚注意到我的代码在Firebug控制台中给了我一个错误.
Update: Just noticed my code gives me an error in the firebug console.
$(this).destroy不是函数
$(this).destroy is not a function
有人可以帮助我吗?
更新:如果我只是执行$(this).remove()
,则该项目将从html中删除.但是,它是否已从DOM中完全删除?还是我还需要以某种方式首先调用该destroy函数?
Update: If I do just $(this).remove()
instead, the item is removed from the html. But is it completely removed from the DOM? Or do I somehow need to call that destroy function first as well?
推荐答案
$(this).dialog('destroy').remove()
这将破坏对话框,然后从DOM中完全删除托管"对话框的div
This will destroy the dialog and then remove the div that was "hosting" the dialog completely from the DOM
这篇关于如何在关闭时完全删除对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!