根据条件打开jQuery对话框

根据条件打开jQuery对话框,jquery,Jquery,如果满足条件,我想打开一个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

如果满足条件,我想打开一个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.");
}

}

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

$('<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'); } }]
                    });
$(“你确定吗?”)
.dialog({
按钮:[{
文本:'是',
单击:函数(){
$(this.dialog('close');
警惕(“在这里做点什么”);
}
}, { 
文本:“否”,
单击:函数(){$(this).dialog('close');}]
});

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

(单击查看源文件)

你必须在你的网站中加入适当的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>
您可以按如下方式调用:

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");
            }
        }
    });
}
功能确认\输入(cref、id、机架、进口日期){
var targetUrl=“boxdestroy.php?custref=“+cref+”&id=“+id+”&rack=“+rack;
return$(“请注意这是一个永久性销毁,无法撤消。只有在确定要销毁此框时才能继续。如果不想销毁,请单击“取消”按钮。”)
.对话({
可调整大小:false,
身高:140,
自动打开:错误,
莫代尔:是的,
按钮:{
“确认”:函数(){
$(此).dialog(“关闭”);
window.location.href=targetUrl;
},
“取消”:函数(){
$(此).dialog(“关闭”);
}
}
});
}

当我单击按钮时,什么也没有发生。所有库都已加载并工作。在萤火虫身上没有什么不寻常的东西。谢谢她没有要求有按钮的对话,他要求有条件的对话。如果对话框有条件地运行dialog(),您在这里看到的内容将在其页面上显示对话框的div。
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");
            }
        }
    });
}