确认模态按钮asp.net的操作

时间:2014-09-05 16:22:31

标签: javascript jquery asp.net prompt

我正在尝试在用户点击下方模式的“取消”按钮时添加提示。 它会提示他们确认动作。下面的代码是我目前尝试的。

function ShowAddEditExecutive() {
        $("#addEditExecutive").dialog({
            modal: true,
            width: 800,
            appendTo: "form",
            open: function () {
                $(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 () {

                    $(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)

如果您想创建一种确认操作的原生方式,可以使用confirm提示用户选择是否继续,这里是您应该在代码中执行的操作

"Cancel": function () {
    if(confirm("Are you sure you want to cancel ?"))
    {
        //code if yes
        $(this).dialog("close");
    }
    else
    {
        //code if no, don't do anything in your case, or don't use the else
    }
}

这是usage example

另一种方式如果你想让它看起来与你的设计相同,你可以创建一个自定义<div>,其中包含用户是否同意或想要继续的确认文本,然后{{1}它使用style并使用CSS来处理事件。