我试图使用confirm方法,但出现了多次确认窗口。我在Google上搜索并尝试了不同的方法,但不幸的是我不能正确地运行它。代码如下:
//user clicks on the delete button
$("#deletePopUpImage").click(function(){
console.log("deletePopUpimageCalled");
//get the id of the image
id = ($(this).parent().prop("id"));
//create the ajax request
data = "typ=function&functionType=deleteUserImage&id="+id;
//open the confirm box
var r = confirm("Are you sure that you want to delete this image?");
if (r == true) {
console.log("loadAjaxCAlled");
//Ajax call
loadAjax(data);
//hide the image and the loader
hideImagePopup();
} else {
//do nothing
}
});
奇怪的是,有时确认窗口会弹出两次,有时会弹出三次,而有时则如预期地只弹出一次。这就是插入了两个console.logs的原因。
“deletePopUpimageCalled”始终只出现一次。但是,“loadAjaxCAlled”会出现多次。
在Ajax请求的成功回调中,我只隐藏了缩略图div。
你知道上面的代码有什么问题吗?
谢谢 Stefan
两次
或三次
。禁用第一次点击并检查结果。 - Rajeev Kumar