Best way to remove an event handler in jQuery?

前端 未结 20 2678
庸人自扰
庸人自扰 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:44

    You may be adding the onclick handler as inline markup:

    
    

    If so, the jquery .off() or .unbind() won't work. You need to add the original event handler in jquery as well:

    $("#addreport").on("click", "", function (e) {
       openAdd();
    });
    

    Then the jquery has a reference to the event handler and can remove it:

    $("#addreport").off("click")
    

    VoidKing mentions this a little more obliquely in a comment above.

提交回复
热议问题