Best way to remove an event handler in jQuery?

前端 未结 20 2329
庸人自扰
庸人自扰 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 12:04

    if you set the onclick via html you need to removeAttr ($(this).removeAttr('onclick'))

    if you set it via jquery (as the after the first click in my examples above) then you need to unbind($(this).unbind('click'))

    0 讨论(0)
  • 2020-11-21 12:05

    If you use $(document).on() to add a listener to a dynamically created element then you may have to use the following to remove it:

    // add the listener
    $(document).on('click','.element',function(){
        // stuff
    });
    
    // remove the listener
    $(document).off("click", ".element");
    
    
    0 讨论(0)
提交回复
热议问题