销毁后如何重新创建jquery对话框 [英] How to recreate jquery dialog after destroy

查看:19
本文介绍了销毁后如何重新创建jquery对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在页面加载时创建了三个模式对话框(使用 $(document).ready(function() {).我通过调用 setDialogWindows() 方法,并将对话框的 div 传递给它.对话框创建代码如下:

I'm creating three modal dialogs on page load (using $(document).ready(function() {). I create these dialogs by calling a setDialogWindows() method, and pass it the div for the dialog. Dialog creation code is below:

function setDialogWindows($element) {
 $element.dialog({
  autoOpen: false,
  modal: true,
  show: 'blind',
  hide: 'blind',
  width: 600,
  resizable: false,
  buttons: {
   Cancel: function() {
    $(this).dialog('destroy');
   },
   'Save': function() {
    $(this).dialog('close');
   }
  }
 });
}

我会为您省去对话框 html,但是当用户单击取消"时,我希望完全重置一些 jquery 拖放功能.因此 $(this).dialog('destroy').但是,当我再次单击链接以打开对话框时,它没有显示出来.我意识到这是因为我没有重新启动它,但我真的不能这样做,因为对话框是在页面加载时创建的.我尝试向 Cancel 函数添加各种递归调用:

I'll spare you the dialog html, but there is some jquery drag/drop functionality that I want to be completely reset when the user clicks Cancel. Hence the $(this).dialog('destroy'). However, when I click the link again to open the dialog box, it doesn't show up. I realize this is because I haven't re-inited it, but I really can't do that because the dialogs are created on page load. I tried adding a recursive call of sorts to the Cancel function as such:

   Cancel: function() {
    $(this).dialog('destroy');
    setDialogWindows($element);
   },

但这不起作用——当我点击应该打开它的链接时,仍然没有打开任何东西.有没有办法重新创建对话框?如果我现在唯一要做的地方是 document.ready,那么我应该在哪里重新初始化对话框有什么想法吗?

But that doesn't work -- still nothing opens when I click the link that should open it. Is there a way to just recreate the dialog box? Any ideas on where I should be re-initializing the dialog if the only place I do it now is on document.ready?

谢谢.

推荐答案

您可以将 setDialogWindows 移动到点击处理程序中并将 autoOpen 设置为 true,类似于:

You can move setDialogWindows into a click handler and turn autoOpen to true, something like:

$('path/to/clickable/elements').click(function(){
  setDialogWindows($element);
});

这将在每次单击时初始化对话框,并在关闭时将其销毁.

This will initialize the dialog on every click, and destroy it when it is closed.

您也可以只打开单独的对话框,一个带有拖放功能,另一个没有它.

You could also just open up separate dialogs, one with the drag and drop functionality, and another without it.

这篇关于销毁后如何重新创建jquery对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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