Removing the Event Listener on a Button programatically

后端 未结 2 1176
无人及你
无人及你 2021-01-18 15:22

I have a Button which is registered with a onclick event as shown



        
2条回答
  •  不要未来只要你来
    2021-01-18 16:08

    You could set the onclick attribute to null.

    var el = document.getElementById('inputId');
    el.onclick = null;
    

    or better just remove the attribute altogether with the removeAttribute() docs method of the element.

    var el = document.getElementById('inputId');
    el.removeAttribute('onclick');
    

    you will need to add an id to the element though for this..

    example code at http://jsfiddle.net/gaby/PBjtZ/

提交回复
热议问题