【问题标题】:jQuery UI close Dialog when form submitted提交表单时jQuery UI关闭对话框
【发布时间】:2010-08-09 16:44:04
【问题描述】:

我一直在尝试执行以下操作:

  • 在 jQuery 对话框中显示表单
  • 提交表单后,jQuery 对话框应该关闭

我正在尝试以下代码:

    $('#RegisterDialog').dialog({
               autoOpen: false,
                closeOnEscape: false,
                position: 'center',
                modal: true,
                width: 600,
                buttons: {
                    "Cancel account registration": function() { 
                        $(this).dialog("close"); 
                        window.location = 'http://localhost/';
                    } 
                }
});

$(".Register").click(function() {
           $('#RegisterDialog').dialog("close"); 
           $('#RegisterDialog').hide();
});

但是,它会隐藏并再次弹出。我也试过'autoClose:false'。

有什么帮助吗?

【问题讨论】:

  • 嗯,只是一个注释。这在文档加载时执行。这会是个问题吗?当表单被执行时,它会查询同一页面。
  • 当前你有 autoOpen: false,页面加载后不应该弹出对话框。那么你如何显示你的对话框, $('#RegisterDialog').dialog("open");触发了?

标签: javascript jquery forms dialog modal-dialog


【解决方案1】:

你应该试试.remove()

这将删除元素并且它不会再次弹出。

【讨论】:

    【解决方案2】:

    来自 jQuery 文档...

    .dialog( "destroy" ) 
    // Remove the dialog functionality completely. This will return the element back to its pre-init state.
    

    这可能会奏效。

    【讨论】:

      【解决方案3】:

      我认为你应该这样做

      $(".Register").click(function() {
                 $('#RegisterDialog').dialog("close"); 
                 //$('#RegisterDialog').hide(); --> no need to call this
      });
      

      【讨论】:

      • 刚试过;不起作用。我也尝试过 .dialog("destroy") 但这也不起作用。它会消失一秒钟,然后马上回来。似乎有什么东西一直触发它回来
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-04
      相关资源
      最近更新 更多