jQuery UI dialogs: how to close dialog when click outside?

后端 未结 5 1019
夕颜
夕颜 2020-12-15 13:24

In docs I didn\'t see such information.

There are options to close dialog in such cases:

1) push Esc;

2) click on \"OK\" or \"Close\" buttons in the

5条回答
  •  情话喂你
    2020-12-15 14:02

    This is my solution.

    I have, for example

    Some content in here
    Different content in here
    And so on...

    Each div gets opened as a dialog depending on what the user interacts with. So being able to close the currently active one, I do this.

    // This closes the dialog when the user clicks outside of it.
    $("body").on('click', '.ui-widget-overlay', function() {
        if( $("div.ui-dialog").is(":visible") )
        {
            var openDialogId = $(".ui-dialog").find(".ui-dialog-content:visible").attr("id");
            if ($("#"+openDialogId).dialog("isOpen"))
            {
                $("#"+openDialogId).dialog('close');
            }
        }        
    });
    

提交回复
热议问题