在类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();
});
}