jquery UI对话框 - 每当打开对话框时,请确保关闭所有其他对话框

时间:2022-08-26 09:00:52

I have an app that has multiple UI Dialogs... How can I smartly make sure you can't open 2 dialogs. So whenever you open a Dialog it closes any currently open UI Dialogs.

我有一个具有多个UI对话框的应用程序...我如何巧妙地确保您无法打开2个对话框。因此,无论何时打开Dialog,它都会关闭所有当前打开的UI对话框。

3 个解决方案

#1


8  

All dialogs get the ui-dialog-content class added, so you can just do this when opening your dialog:

所有对话框都添加了ui-dialog-content类,因此您可以在打开对话框时执行此操作:

$(".ui-dialog-content").dialog("close");
$("#myDialog").dialog("open");

#2


1  

If you're using jquery-ui dialog, you should be able to use something similar to $(".selectorClass").dialog("destroy") to reset all dialogs back to their original (hidden) states. (Making sure to put in your own selector class/ID of course!)

如果你正在使用jquery-ui对话框,你应该可以使用类似于$(“。selectorClass”)。dialog(“destroy”)的东西来将所有对话框重置回其原始(隐藏)状态。 (当然要确保放入自己的选择器类/ ID!)

For more information, check out http://jqueryui.com/demos/dialog/

有关更多信息,请访问http://jqueryui.com/demos/dialog/

#3


1  

Assuming you didn't want to actually restrict users' ability to open more than one dialog by making each dialog modal (so they can't click anywhere on the page until the dialog is deliberately closed), I would say you want to cache your dialogs in a variable and then iterate through this array to close them all before opening the target. Without testing what I'm writing here, try something along these lines:

假设您不想通过使每个对话框模态实际限制用户打开多个对话框的能力(因此在故意关闭对话框之前他们无法单击页面上的任何位置),我会说您想要缓存您的变量中的对话框,然后在打开目标之前遍历此数组以关闭它们。如果不测试我在这里写的内容,请尝试以下几点:

var options = {
    autoOpen: false,
    modal: true,
    ...
};

var dlg = $('dialog-candidate-' + n);

$(dlg).each(function(i) {
    $(this).dialog(options);
    $('#dialog-trigger-' + n).click(function() {
        for(var i = 0; i<= dlg.length; i++) {
          dlg[0].dialog("close");
        }
        $(this).dialog("open");
        return false;
    });
    n++;
});

#1


8  

All dialogs get the ui-dialog-content class added, so you can just do this when opening your dialog:

所有对话框都添加了ui-dialog-content类,因此您可以在打开对话框时执行此操作:

$(".ui-dialog-content").dialog("close");
$("#myDialog").dialog("open");

#2


1  

If you're using jquery-ui dialog, you should be able to use something similar to $(".selectorClass").dialog("destroy") to reset all dialogs back to their original (hidden) states. (Making sure to put in your own selector class/ID of course!)

如果你正在使用jquery-ui对话框,你应该可以使用类似于$(“。selectorClass”)。dialog(“destroy”)的东西来将所有对话框重置回其原始(隐藏)状态。 (当然要确保放入自己的选择器类/ ID!)

For more information, check out http://jqueryui.com/demos/dialog/

有关更多信息,请访问http://jqueryui.com/demos/dialog/

#3


1  

Assuming you didn't want to actually restrict users' ability to open more than one dialog by making each dialog modal (so they can't click anywhere on the page until the dialog is deliberately closed), I would say you want to cache your dialogs in a variable and then iterate through this array to close them all before opening the target. Without testing what I'm writing here, try something along these lines:

假设您不想通过使每个对话框模态实际限制用户打开多个对话框的能力(因此在故意关闭对话框之前他们无法单击页面上的任何位置),我会说您想要缓存您的变量中的对话框,然后在打开目标之前遍历此数组以关闭它们。如果不测试我在这里写的内容,请尝试以下几点:

var options = {
    autoOpen: false,
    modal: true,
    ...
};

var dlg = $('dialog-candidate-' + n);

$(dlg).each(function(i) {
    $(this).dialog(options);
    $('#dialog-trigger-' + n).click(function() {
        for(var i = 0; i<= dlg.length; i++) {
          dlg[0].dialog("close");
        }
        $(this).dialog("open");
        return false;
    });
    n++;
});