类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(); }); }
相关文章推荐
- javascrpt绑定事件之匿名函数无法解除绑定问题
- 一个小问题: a标签句柄绑定事件时,函数名是search时报错
- 冒泡,setinterval,背景图的div绑定事件,匿名函数问题--工作中的思考
- javascrpt绑定事件之匿名函数无法解除绑定问题
- addEventListener()解决传统事件绑定中去除冗余同名函数但也存在问题
- jquery中事件重复绑定以及解绑问题
- 【js学习之路】事件绑定函数中,将this换成调用对象导致的问题
- eslint => Jq事件绑定使用箭头函数问题
- 在一个事件上绑定多个函数
- Silverlight 2 学习笔记之事件的重复绑定问题
- Silverlight 2 学习笔记之事件的重复绑定问题
- JS 事件绑定函数代码
- updatepanel中动态生成组件及绑定事件问题的解决
- silverlight中DataGrid的滚动条绑定事件问题
- jquery 新建的元素事件绑定问题
- IQueryable<T>绑定到Repeater,执行Repeater_ItemDataBound事件时,遇到的问题及解决办法
- JavaScript绑定事件时的闭包问题
- javascript事件绑定后this变义问题的解决[prototype1.5.1]
- jquery:DOM更改后重新绑定事件的问题