我正在尝试创建多个对话框,有些我无法理解如何创建这些对话框。
DIV's
对于每个对话框,我都有每个操作的消息。基本上,如果用户检查CheckBox
然后出现对话框,说明您要确认此操作。一段时间后,如果用户再次取消选中该选项,CheckBox
则会出现另一个带有差异消息的对话框。请帮我解决这个问题。
这是我到目前为止所得到的。
================
HTML
<div id="dialog-isReceived" title="Mark as Received?">
Are you sure you want to mark this order as "Received"? <br />
The customer will receive an email confirming their order is ready for collection.
</div>
<div id="dialog-notReceived" title="Mark as Not Received?">
Are you sure you want to mark this order as "Not Received"? <br />
</div>
jQuery
var isReceivedCheckBox = $('.isReceivedCheckBox input[type=checkbox]');
var dialogId; //trying to pass the Id of the div dynamically BUT not working
var result;
$(document).ready(function () {
$(dialogId).dialog(
{
autoOpen: false,
width: 300,
height: 200,
resizable: false,
modal: false,
buttons: {
"Confirm": function () {
result = true;
},
Cancel: function () {
result = false;
$(this).dialog("close");
}
},
});
});
======================
我要执行的代码
$(document).on("change",isReceivedCheckBox, function () {
var checked = $(this).is(':checked');
if (checked) {
dialogId = "'#dialog-isReceived'"; //setting the DIV ID here and hoping that dialog will appears.
$(dialogId).dialog('open');
if(!result)
$(this).attr("checked", false); // if user clicks cancel on dialog then do not check the checkbox
} else {
dialogId = "'#dialog-notReceived'";
$(dialogId).dialog('open');
if(!result)
$(this).attr("checked", true); //if user clicks cancel on dialog then do not uncheck the checkbox because it was checked previously
}
});
这里的问题是对话框永远不会出现,因为当页面加载时我的所有 div 都是可见的,因为我无法dialogID
在页面加载时设置变量。此外,我在此页面上至少有 5 个对话框执行相同的功能。如果您能提出更好的方法或告诉我我在这里做错了什么,将非常感激。
谢谢,米兰P