組み込みの確認ボックスと同じように、javascipt でカスタムメイドの確認ボックスを作成したいと考えています。組み込みの確認ボックスでは、ユーザーが少なくとも 1 つのことを選択しない限り、コードを進めることができません。以下は私のコードです: * ** * * HTML 開始* ** * *
<div class = "popUp confirm" style="z-index:40000;" id="confirmBlock">
<div id = "confirmLabel" >Confirm Message</div>
<div style ="border:0px solid red;height:44.56px;">
<input id="Confirm" type="button" value="Confirm" onclick = "confirmAction(1)" />
<input id = "CancelConfirm" type="button" value="Cancel" onclick = "confirmAction(0)" />
</div>
</div>
** * ** HTML終了* ** * *
** * ** Javascript の開始* ** * *
var confirmresult = "-1";
function confirmationLoop()
{
alert("If this alert is preesnt it works, seems like the built in alert provides some sort of pause for other parts of code to continue to work");
if(confirmresult == "-1")
confirmationLoop();
return;
}
function confirmAction(val)
{
confirmresult = val;
}
function checkuuu()
{
confirmresult = "1";
}
function confirmMessage(message)
{
document.getElementById("confirmLabel").innerHTML= message;
//var check = setTimeout(function(){confirmAction(1)},5000);
confirmationLoop();
/*
while(1) //using while almost does not allow any other part to run at all hence tried recursion
{
if(confirmresult != "-1")
break;
}
*/
document.getElementById("confirmLabel").innerHTML= "Confirm Message";
var returnVal = confirmresult;
confirmresult = -1;
return returnVal;
}
** * ** Javascript終了* ** * *
** * **サンプルコードの開始* ** * * だから、これは私が以下に期待するものです:
function example
{
var check = confirmMessage(message);
//the next part of code should not execute untill i press confirm or cancel, using settimeout or settimeinterval is asynchronous and the code flow continues. i want the effect something like alert and confirm built in boxes
}
** * **サンプルコード終了* ** * *
ループを使用しましたが、スレッドが完全に占有されたままになり、ボタンを押す機会がありません。これは明らかでした。ただし、再帰により、他のアクティビティを自由に実行できます。確認ボタンを押すとconfirmResultの値が1になり、アラートで確認しても問題はありません。再帰ループ、つまり確認ループは 1 として読み取られないようです。それでも -1 として続きます。その確認ループにアラートを入れると、値は 1 として読み取られます。Ps=> 大変な質問で申し訳ありません!!!