如果满足条件,我想打开一个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.");
}
}
答案 0 :(得分:1)
您可以按如下方式致电jQuery UI Dialog:
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");
}
}
});
}
答案 1 :(得分: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'); } }]
});
答案 2 :(得分:-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" );
}
}
});
});