Best way to remove an event handler in jQuery?

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

    I know this comes in late, but why not use plain JS to remove the event?

    var myElement = document.getElementById("your_ID");
    myElement.onclick = null;
    

    or, if you use a named function as an event handler:

    function eh(event){...}
    var myElement = document.getElementById("your_ID");
    myElement.addEventListener("click",eh); // add event handler
    myElement.removeEventListener("click",eh); //remove it
    

提交回复
热议问题