将模式弹出窗体上所选按钮的值或名称存储到变量中

Storing the value or name of the button selected on a modal popup form to a variable

本文关键字:存储 变量 按钮 模式 窗体      更新时间:2023-09-26

我正在使用javascript确认来跟踪用户是否点击了确定或取消。确认不容易造型,我想要更好的外观。如何应用函数确认下面的对话框,以便我可以确定用户是单击确定还是取消并存储变量中的结果请继续。

        var pleaseContinue = true;
        if (firstForm.length > 0) {
         pleaseContinue = confirm("All the data that is not saved will be lost.Do you want to proceed ? ");
        }
        if pleaseContinue()
        {
            //do something
        }
        var confirmed = false;
        function confirmDialog(obj)
        {
            if(!confirmed)
            {
                $( "#dialog-confirm" ).dialog({
                    resizable: false,
                    height:140,
                    modal: true,
                    buttons: {
                        "Yes": function()
                        {
                            $( this ).dialog( "close" );
                            confirmed = true; obj.click();
                        },
                        "No": function()
                        {
                            $( this ).dialog( "close" );
                        }
                    }
                });
            }
            return confirmed;
        }

你不能这样做:确认功能被阻止,如果你使用的是基于 HTML 的表单,你需要处理事件。请改用回调函数:

function confirmDialog(onok)
{
    $( "#dialog-confirm" ).dialog({
        resizable: false,
        height:140,
        modal: true,
        buttons: {
            "Yes": function()
            {
                $( this ).dialog( "close" );
                onok();
            },
            "No": function()
            {
                $( this ).dialog( "close" );
            }
        }
    });
}