Close dialog on click (anywhere)

前端 未结 10 1177
旧时难觅i
旧时难觅i 2020-11-30 23:34

Is there a default option to close a jQuery dialog by clicking somewhere on the screen instead of the close icon?

10条回答
  •  南笙
    南笙 (楼主)
    2020-12-01 00:19

    If you have several dialogs that could be opened on a page, this will allow any of them to be closed by clicking on the background:

    $('body').on('click','.ui-widget-overlay', function() {
        $('.ui-dialog').filter(function () {
        return $(this).css("display") === "block";
        }).find('.ui-dialog-content').dialog('close');
    });
    

    (Only works for modal dialogs, as it relies on '.ui-widget-overlay'. And it does close all open dialogs any time the background of one of them is clicked.)

提交回复
热议问题