我有以下jQuery代码:
//The user clicked on a species to delete it. We need to use event delegation because items are added dynamically.
$('#speciesAdded').on('click', 'li', function (event) {
// Let's make sure this is what the user wants to do?
alertify.confirm("Do you wish to delete the sighting?", function (e) {
if (e) {
// User clicked Ok - No need to do anything
} else {
// User clicked cancel
return;
}
});
alert("Howdy!");
...
...
});
当此触发时,JavaScript警报对话框会同时显示 作为警报确认对话框。换句话说,在用户甚至有机会确认操作之前执行alertify之后发生的代码。我不知道这里发生了什么我怎么能阻止这个?
答案 0 :(得分:1)
我想你想把你的警报方法调用放在确认回调中......
$('#speciesAdded').on('click', 'li', function (event) {
// Let's make sure this is what the user wants to do?
alertify.confirm("Do you wish to delete the sighting?", function (e) {
if (e) {
// User clicked Ok - No need to do anything
// Do something on okay
alert("Howdy!");
...
...
} else {
// User clicked cancel
//
return;
}
});
});