Jquery UI Close Dialog & Open New Dialog

杀马特。学长 韩版系。学妹 提交于 2019-12-23 04:29:18

问题


The concept seems simple enough, yet i'm having a lot problems executing it.

I need to close the current dialog and open another. It does close the #imageModal, but does not open the #uploadModal.

Any suggestions?

Edit: Added the #uploadModal

$("#imageModal").dialog({
    autoOpen: false,
    height: 500,
    width: 500,
    modal: true,
    closeOnEscape: true,
    resizable: false,
    buttons: {
        'Upload Image': function() {
            // CLOSE 1 DIALOG AND OPEN ANOTHER
            $(this).dialog('close');
            $('#uploadModal').dialog('open');

        },
        Cancel: function() {
            $(this).dialog('close');
        }
    },
    close: function() {
        $(this).dialog('close');
    }
});


$("#uploadModal").dialog({
    autoOpen: false,
    height: 500,
    width: 500,
    modal: true,
    closeOnEscape: true,
    resizable: false,
    buttons: {
        'Upload Image': function() {


        },
        Cancel: function() {
            $(this).dialog('close');
        }
    },
    close: function() {
        $(this).dialog('close');
    }
});         

回答1:


Use the callback function that is executed when the dialog has finished his task.

[...]
'Upload Image': function() {
                // CLOSE 1 DIALOG AND OPEN ANOTHER
                $(this).dialog('close', function() {
                     $('#uploadModal').dialog('open');
                });

}, 
[...]



回答2:


Hmm, have u change the order of close and open? Let´s say, first open the next dialog, then closes the first one?

1 - This;

// CLOSE 1 DIALOG AND OPEN ANOTHER
   $(this).dialog('close');
   $('#uploadModal').dialog('open');

2 - To:

// CLOSE 1 DIALOG AND OPEN ANOTHER
   $('#uploadModal').dialog('open');
   $(this).dialog('close');



回答3:


$(this).dialog('close');
$('#uploadModal').dialog('open');

This actually works fine for me (jquery 1.7 jquery-ui 1.8). The suggested answer only closes the dialog and doesn't open the new one.




回答4:


Try wrapping your "uploadModal" open call in a setTimeout.

'Upload Image': function() { 
    // CLOSE 1 DIALOG AND OPEN ANOTHER 
    $(this).dialog('close'); 
    setTimeout(function () {
        $('#uploadModal').dialog('open');
    }, 100);
}, 

You could also bind to the close event of the dialog via..

$("#uploadImage").bind("dialogClose", function () {
    // code goes here
});

but I think the first will work fine for what you want.




回答5:


Yeah, this has been up here for a bit. I was searching on how to fix the same issue. I posted up more code then needed so you can see whats going on. I used the name of the current dialog to close and the name of the new one to open. Works...

//============= User Modal ===============================//

$( "#dialog-message" ).dialog({
    autoOpen: false,
    modal: true,
    resizable: false,
    width: 650,
    buttons: {
        Add: function() {
            $('#dialog-message').dialog( "close" );
            $('#dialog-message3').dialog( "open" );
        }
    }
});

$( "#opener" ).click(function() {
    $( "#dialog-message" ).dialog( "open" );
    return false;
}); 

//========== Add User Modal ============================ // 
$( "#dialog-message3" ).dialog({
    autoOpen: false,
    modal: true,
    resizable: false,
    width: 250,
    buttons: {
        Save: function() {
            $( '#dialog-message3' ).dialog( "close" );
        }
    }
});


来源:https://stackoverflow.com/questions/5718261/jquery-ui-close-dialog-open-new-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!