【问题标题】:How to close parent dialog box from child dialog box which is opened by parent close button click event?如何从父关闭按钮单击事件打开的子对话框中关闭父对话框?
【发布时间】:2015-05-08 02:44:32
【问题描述】:

我正在尝试从另一个对话框(子)中关闭一个对话框(父),该对话框是在父对话框关闭按钮“X”上打开的。

我可以通过单击父对话框关闭按钮“X”事件将确认框(带有是、否按钮)显示为子对话框。

当用户单击子对话框的“是”按钮时,我面临关闭父对话框的困难。

这是我的代码:

ParentDialog = function () {
  $("#fullscreen").dialog({
    title: "Simple Step Wizard",
    position: ["left", "top"],
    width: "100%",
    height: $(window).height(),
    zIndex: 1000,
    modal: true,
    open: function (event, ui) {$("#left-panel").hide();},
    close: function (event, ui) {                    
      ChildDialog();
    }
  });
}

子对话框:

ChildDialog = function () {
  $("#Confirm").dialog({
    modal: true,
    title: 'Please Confirm',
    zIndex: 10000,
    autoOpen: true,
    width: 'auto',
    resizable: false,
    buttons: {
      Yes: function () {
        $(this).dialog("close");
        //ParentDialog.Close() ??
      },
      No: function () {
        $(this).dialog("close");
      }
    },
    close: function (event, ui) {
      //$(this).remove();
    }
  });
}

【问题讨论】:

  • 正确缩进代码

标签: jquery html twitter-bootstrap jquery-dialog


【解决方案1】:

jQuery UI 对话框有.close() method。文档中写的示例是这样的:

$( ".selector" ).dialog( "close" );

将此示例改编为您的代码,我建议您尝试一下:

ChildDialog = function () {
    $("#Confirm").dialog({
        buttons: {
            Yes: function () {
                $(this).dialog("close");
                $("#fullscreen").dialog("close"); //add this line
            },
            No: function () {
                $(this).dialog("close");
            }
        }
    });
}

【讨论】:

    猜你喜欢
    • 2013-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-05
    相关资源
    最近更新 更多