【发布时间】:2015-10-12 09:06:30
【问题描述】:
我正在尝试使用确认方法,但由于某种原因,确认窗口会弹出几次。我用谷歌搜索并尝试了不同的东西,但不幸的是我无法让它正常运行。代码如下:
//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。
你知道我上面的代码有什么问题吗?
谢谢 斯蒂芬
【问题讨论】:
-
您可能不小心点击了图片
twice或thrice。禁用点击您的first click并检查结果 -
你试过在回调中调用ajax方法吗?
-
@RajeevKumar 我将如何禁用点击事件?通过添加通过 jquery 禁用的属性?
标签: javascript confirm