1

如果满足条件,我想打开一个 jquery 对话窗口。目前我只使用基本的确认和警报条件,但会改为对话。我熟悉对话框,但不熟悉如何从函数调用。我将如何修改我的代码来做到这一点?非常感谢

function confirm_entry(cref,id,rack,intakedate)
{
input_box=confirm("Please be aware that this is a permanent destruction and cannot be undone. Only proceed if you are sure you wish to destroy this box. If not, click the cancel button.");
if (input_box==true)

{ 
// Output when OK is clicked
 window.location.href =  "boxdestroy.php?custref="+cref+"&id="+id+"&rack="+rack; 
}

else
{
// Output when Cancel is clicked
alert ("Thank you. Your destruction has been cancelled and no further action will be taken.");
}

}
4

3 回答 3

1

您可以按如下方式调用jQuery UI 对话框:

function confirm_entry(cref, id, rack, intakedate) {
    var targetUrl = "boxdestroy.php?custref="+cref+"&id="+id+"&rack="+rack;
    return $("<div class='dialog' title='Confirmation Required'>Please be aware that this is a permanent destruction and cannot be undone. Only proceed if you are sure you wish to destroy this box. If not, click the cancel button.</div>")
    .dialog({
        resizable: false,
        height:140,
        autoOpen: false,
        modal: true,
        buttons: {
            "Confirm": function() {
                $(this).dialog("close");
                window.location.href = targetUrl;
            },
            "Cancel": function() {
                $(this).dialog("close");
            }
        }
    });
}
于 2012-10-27T12:26:44.580 回答
0

这将打开一个对话框,该对话框将在是时发出警报并关闭,而在否时将关闭

$('<div>are you sure?</div>')
                   .dialog({ 
                        buttons: [{ 
                            text: 'yes',
                            click: function () {                                
                                $(this).dialog('close');
                              alert('do something here');
                            }
                        }, { 
                             text: 'no', 
                             click: function () { $(this).dialog('close'); } }]
                    });
于 2012-10-27T11:16:38.850 回答
-1

实际上您的问题的答案在 Jquery UI 网站中:

http://jqueryui.com/dialog/#modal-confirmation(点击查看源码

您必须将正确的 html 放入您的网站

<div id="dialog-confirm" title="Empty the recycle bin?">
    <p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>These items will be permanently deleted and cannot be recovered. Are you sure?</p>
</div>

然后将 js 动作绑定到它:

$(function() {
        $( "#dialog-confirm" ).dialog({
            resizable: false,
            height:140,
            modal: true,
            buttons: {
                "Delete all items": function() {
                    $( this ).dialog( "close" );
                },
                Cancel: function() {
                    $( this ).dialog( "close" );
                }
            }
        });
    });
于 2012-10-27T11:16:46.977 回答