Best way to remove an event handler in jQuery?

前端 未结 20 2327
庸人自扰
庸人自扰 2020-11-21 11:38

I have an input type=\"image\". This acts like the cell notes in Microsoft Excel. If someone enters a number into the text box that this input-image

20条回答
  •  长情又很酷
    2020-11-21 11:56

    If you want to respond to an event just one time, the following syntax should be really helpful:

     $('.myLink').bind('click', function() {
       //do some things
    
       $(this).unbind('click', arguments.callee); //unbind *just this handler*
     });
    

    Using arguments.callee, we can ensure that the one specific anonymous-function handler is removed, and thus, have a single time handler for a given event. Hope this helps others.

提交回复
热议问题