【问题标题】:Confirm action for modal button asp.net确认模式按钮 asp.net 的操作
【发布时间】:2014-09-05 16:22:30
【问题描述】:

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

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

    });


    }

【问题讨论】:

  • 代码有什么问题?
  • 这段代码没有问题,我正在努力让“取消”按钮弹出一个确认窗口。

标签: javascript jquery asp.net prompt


【解决方案1】:

如果您想创建一个原生方式来确认操作,您可以使用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>,其中包含用户是否同意或想要继续的确认文本,然后style它使用CSS 并使用jQuery onclick function 处理事件。

【讨论】:

  • 您先生是圣人。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-13
  • 2019-01-06
相关资源
最近更新 更多