-1
我已經以下代碼:如何在執行javascript中的其他語句之前等待bootbox.prompt()結果?
var bootboxresult;
bootbox.prompt('Please enter some data', function(result) {
if (result != null) {
bootboxresult = result;
}});
alert(bootboxresult);
if(bootboxresult === null)
{
return;
}
if(bootboxresult != null)
{
Some Code To Excecute
}
代碼顯示提示框,但始終是「bootboxresult」的內容是可變的空或未定義。
我需要進一步的代碼應該等待bootbox.prompt()將值存儲在「bootboxresult」變量中。
請指教。
的[我如何返回從一個異步調用的響應?(可能的複製http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an - 異步調用) – CBroe
謝謝@CBroe,它幫助並清除了我的同步和異步調用概念。 –