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

时间:2014-09-05 18:06:10

标签: javascript jquery asp.net modal-dialog

我有一个模态。

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

我还需要弄清楚如何默认使用此方法的“添加/编辑执行信息”按钮:$(this).closest('。ui-dialog')。find('。ui-dialog-buttonpane 。按钮:当量(0)')聚焦();要关注按钮,但当用户在文本框中单击时,然后在文本框外部,它会取消按钮。

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');
        },

    });


    }

1 个答案:

答案 0 :(得分:0)

使用prompt()解决; Jquery命令