How to bind, unbind and rebind (click) events in JQuery

前端 未结 2 1356
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 05:57

After asking the same question 2 weeks ago here, I finally found \"the\" solution. This is why I am answering my own question. ;)

HOW TO BIND, UNBIND AND REB

2条回答
  •  独厮守ぢ
    2020-12-03 06:06

    A simpler and short solution is to add a class to the object if you want to unbind it then remove this class to rebind ex;

    $('#button').click( function(){
       if($(this).hasClass('unbinded')) return;
       //Do somthing
     });
    
    $('#toggle').click(function(){
        $('#button').toggleClass('unbinded');
     });
    

提交回复
热议问题