3

我在 WebForms 中有一个 jQuery 脚本,我试图在按钮单击事件上显示一条消息。我的文件script中有,我.aspx在代码隐藏中调用它。confirm问题是如果用户单击而不是cancel按钮,我如何重定向?

.ASPX 脚本:

<script type="text/javascript">

        $(window).unload(function () {
            CloseWindow();
        })
        //var newEmployeeDetail = document.getElementById(hfNe)

        function confirmAppointEmployee() {
            debugger;
            Messi.ask("Employee appointed successfully",
                function (val) {
                    if (val == false) {
                    $("[id*=Cancel]").click();
                }
                else {
                        $("[id*=Confirm]").click();
                }

            }, {
                buttons: [{ id: '0', label: 'Confirm', val: true, 'class': 'btn-primary' }, { id: '0', label: 'Cancel', val: false }]
            });
        }

    </script>

代码背后:

 ClientScript.RegisterStartupScript(this.GetType(), "Success", "<script>confirmQuickAppointEmployee()</script>"); 

下面的代码是重定向用户需要调用的字符串。

private string PersonalInformationDetailUrl = Company.Framework.SmartNavigationPersonnel.SmartNavigation.GetUrlByPageName(Company.Framework.SmartNavigationPersonnel.SmartNavigation.PageNameList.PersonalInformationDetail) + "?AllowAddOption=true&AllowDeleteOption=true&RefreshMenuPage=true";

我尝试了以下方法,但cancelconfirm按钮都做同样的事情。

  var confirm = "$(document).ready(function(){ new Messi('Employee appointed successfully', " +
                        "{title: 'Title', buttons: [{id: 0, label: 'Close', val: 'false'},{id: 0, label: 'Confirm', val: 'true'}], " +
                        "callback: function(val) { window.location.href = '" + Functions.FixClientUrl(PersonalInformationDetailUrl) + "' }}); });";
                    this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "confirm", confirm, true);
4

1 回答 1

0

这一切都归结为您的confirmQuickAppointEmployeeJavascript 函数,该函数未在问题中指定。很明显,它必须是一个确认对话框/窗口,您可以在其中有一个确认和一个取消按钮/功能。但是,由于问题中没有共享实现,我只能提供一般准则:

找出那个函数是什么

打开浏览器的开发工具,转到其控制台选项卡并输入:

confirmQuickAppointEmployee + ""

然后按 Enter。这将向您显示此函数的源代码(如果存在)。当然,您应该在您的网站上执行此测试。查看此函数的源代码可能会为您提供一些有助于找出答案的信息。

查找使用示例

在您的项目源代码中搜索所有出现的confirmQuickAppointEmployee以查看它到目前为止是如何使用的。如果您仔细查看所有用法,那么您可能会发现一些确认/取消不同的示例。如果您找到这样的示例,那么您只需要了解如何识别确认/取消点击并将相同的想法应用于您的问题。

一个潜在可能

Javascript 有一个本机confirm对话框,可以用作函数调用并返回一个布尔值。在您的控制台中尝试此操作:

if (confirm("")) {
    alert("confirmed");
} else {
    alert("cancelled");
}

如果您的 confirmQuickApppointEmployee 碰巧模仿了这种行为,那么您可以类似地使用它。当然,这在很大程度上取决于confirmQuickAppointEmployee问题中没有共享的 。

于 2021-02-15T15:19:43.847 回答