模态中未保存的信息会提示用户在退出模态之前进行保存

unsaved information inside modal prompts user to save before exiting the modal

本文关键字:模态 保存 退出 提示 信息 用户      更新时间:2023-09-26

我有一个模态。

我想用一种方式编写它,当用户点击取消或"转义"时,在文本框中输入任何信息时,它会提示他们保存未保存的信息。

我还需要弄清楚如何默认"添加/编辑高管信息"按钮,我使用的方法是:$(this).closest('.ui dialog').find('.ui对话框按钮窗格按钮:eq(0)').focus();以聚焦按钮,但当用户在文本框内单击,然后在文本框外单击时,它会取消聚焦按钮。

function ShowAddEditExecutive() {
        $("#addEditExecutive").dialog({
            modal: true,
            width: 800,
            appendTo: "form",
            open: function () {
      $(this).closest('.ui-dialog').find('.ui-dialog-buttonpane button:eq(0)').focus();
                 $(this).dialog("widget").find(".ui-dialog-titlebar").show();
                // Removes the do you want to leave this page dialog.
                window.onbeforeunload = null;
                // The two isplalines below are 2 different ways to ensure the 
                // background is completely grayed out if the modal is larger
                // then the page. The first was chosen so that the scroll
                // bars are not disabled.
                $('.ui-widget-overlay').css('position', 'fixed');
               //$('body').css('overflow', 'hidden');
              },
             buttons: {
                "Add/Edit Executive Information": function () {
                    $("[id*=btnAddEditExecutive]").click();
                 },
                "Cancel": function () {  
                        if (confirm("Are you sure you want to cancel ?")) {
                        //code if yes
                       $(this).dialog("close");
                    }
                 }
             },
        close: function (ev, ui) {
            // Ensures when you cancel that the values are not retained.
            $(this).remove();
            // The two lines below are 2 different ways to ensure the 
            // background is completely grayed out if the modal is larger
            // then the page. The first was chosen so that the scroll
            // bars are not disabled.
            $('.ui-widget-overlay').css('position', 'absolute');
            //$('body').css('overflow', 'inline');
        },
    });

    }

使用prompt()求解;Jquery命令