繁体   English   中英

带确认对话框的动作链接

[英]Actionlink with confirmation dialog

我想在链接打开之前显示一条确认消息。 但是,尽管如此,尽管单击了“取消”或关闭对话框,但仍会链接。 请帮助我,因为我对此一直感到困惑。

<div style="float: left; width: 40px; height: 10px; "> @Html.ActionLink("-Pg", "SupprimerPage", "Section", new { pageId = @item.Id }, new { onclick = "ConfirmerSuppressionPage(event);", @class = "editLink", style = "width:30px" })</div>

Javascript:

 function ConfirmerSuppressionPage(event) {
    var x = confirm("Êtes-vous sûr de vouloir supprimer cette page?");
    console.log(x);
    if (x == null) {
        event.preventDefault();
        return false;
    }

    if (x == true) {

        return true;
    }
    else {
        event.preventDefault();
        event.stopPropagation();
    }
}

这可能没有帮助,但是我遇到了类似的问题,即某些浏览器不遵守“取消”按钮,并创建了替换功能来解决该问题:

function showConfirm(str) {
    if (confirm(str) == false) {
        if (typeof (event) != "undefined") {
            event.returnValue = false;
        }

        return false;
    }
    else {
        return true;
    }
}

然后在您的ConfirmerSuppressionPage函数中,将调用替换为showConfirm进行confirm

var result = confirm("Êtes-vous sûr de vouloir supprimer cette page?");
if (result == true) {
    x = "You pressed OK!";
} else {
    x = "You pressed Cancel!";
}

Confirm是一个JavaScript对话框,它将返回truefalse 在用户不单击对话框的“ Yes或“ No按钮之前,JavaScript不会执行下一行。

Any how Confirm will return you True or False, and now you have to deal with it.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM