您的位置:首页 > 其它

类confirm函数内绑定事件问题(解绑)

2016-11-14 00:00 323 查看
在类confirm函数内为取消跟确认按钮绑定事件时很容易出一个问题,就是第一次弹窗时,即使你点击的是取消按钮,但仍然不影响为确认按钮绑定了事件,很容易导致第二次点击确认的时候会执行两次。这个可以为确认按钮随便console一个字符串证实。
为了避免这种情况,需要在点击取消按钮的时候,为确认按钮取消绑定事件

function removeConfirm(alertContent,sureContent){
$("#overMask").show();
$(".sure").html(sureContent);
$(".confirmContent").html(alertContent);
$(".confirmTips").show();
$(".cancel").bind("click",function(e){
$("#overMask").hide();
$(".confirmTips").hide();
console.log(flag);
$(".cancel").unbind("click");
$(".sure").unbind("click");
});

$(".sure").one("click",function(e){
$("#overMask").hide();
$(".confirmTips").hide();
$(".sure").unbind("click");
console.log("12321312");
removeLesson();
});

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: