//自制confirm弹窗
function jqConfirm(method,courseCode,alertContent,sureContent,func){
$("#overMask").show();
$(".sure").html(sureContent);
$(".confirmContent").html(alertContent);
$(".confirmTips").show();
$(".cancel").on("click",function(e){
$("#overMask").hide();
$(".confirmTips").hide();
});
$(".sure").one("click",function(e){
$("#overMask").hide();
$(".confirmTips").hide();
console.log(method);
$.ajax({
type:"post",
url:"../admin-api/plan_course/oper/"+method+"/"+courseCode,
async:true,
data:{params:{courseCode:courseCode}},
contentType:"application/json",
success:function(data){
console.log(JSON.stringify(data));
if(data.resultCode == 1003 || data.resultCode == 1001 || data.resultCode == 1002){
jqAlert(data.errorMessage);
}else{
func();
}
},
error:function(code,msg){
console.log(code,msg);
}
})
});
}
问题当时出现的问题是,弹窗出来后,我用的是为确认按钮绑定事件,要是用on绑定的话,
$(".on")这个按钮在绑定这个事件后,下次再点击,绑定的事件都会再次发生,通俗点说,就是这次给jqConfirm函数传method为settle时,点击$(".on")没有任何问题。但是当下次要传method为reedit时,再次需要点击$(".on")的时候,由于上次已经绑定了一次传settle的事件,再加上后来传reedit的事件,就给$(".on") 绑定了两个事件。
后来用one绑定事件解决了问题