1 回答

TA貢獻1906條經驗 獲得超3個贊
您需要重寫showConfirmationAndWait 以實際等待確認并返回結果。
還將您的整個處理程序標記為async.
async function showConfirmationAndWait() {
try {
await $.alertable.confirm('You sure?');
return true
} catch {
return false
}
}
$(function() {
$('#await').on('click', async function() {
var promiseObj = await showConfirmationAndWait();
console.log('after await promiseObj', promiseObj);
//...... big code with its own function call that i don't want to touch
console.log('Some scary logic goes here. It should be printed after confirmation.');
});
});
<link href="https://cdn.rawgit.com/claviska/jquery-alertable/master/jquery.alertable.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="https://rawgit.com/claviska/jquery-alertable/master/jquery.alertable.min.js"></script>
<button id="await">Show confirmation wait and proceed next line</button>
添加回答
舉報