绑定事件后,某些情况下需要解绑该事件

比如,在做弹窗的时候, “弹出”时,我们让浏览器 禁止滑动(浏览器事件) ;“关闭”弹窗时,我们让浏览器 恢复滑动功能;

下面的例子是 阻止表单默认 提交; 点击按钮 事, 取消阻止表单默认提交;

html:

1 <form action="/123.html">
2     <input type="text">
3     <input id="btnSubmit" type="submit">
4     <button type="button">unlock Submit</button>
5 </form>

js:

 1 $().ready(function(){
 2         $('#btnSubmit').on('click',function(e){
 3             e.preventDefault();
 4         })
 5 
 6         $('button').on('click',function(){
 7             $('#btnSubmit').off('click').on('click',function(e){
 8             return true;
 9             })
10         })
11 
12     });    
原文地址:https://www.cnblogs.com/yesw/p/4364201.html