1 回答
TA贡献1906条经验 获得超2个赞
您需要重写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>
添加回答
举报