複数のダイアログボックスを作成しようとしていますが、それらのダイアログボックスの作成方法を理解できません。
すべてDIV's
のアクションのメッセージがあるダイアログボックスごとにあります。基本的に、ユーザーがチェックCheckBox
すると、このアクションを確認することを示すダイアログが表示されます。そして、しばらくしてからユーザーが再度チェックを外すCheckBox
と、diffメッセージを含む別のダイアログが表示されます。これを手伝ってください。
これが私がこれまでに得たものです。
===============
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
}
});
dialogID
ここでの問題は、ページが読み込まれると、ページの読み込み時に変数を設定できないため、すべてのdivが表示されるため、ダイアログが表示されないことです。また、このページには同じ機能を実行するダイアログが少なくとも5つあります。より良いアプローチを提案したり、ここで私が間違っていることを教えていただければ幸いです。
ありがとう、ミラノP