Javascript method to uncheck the event: You can uncheck the event by deleting the event handler, such as [btn.onclick = null;].
#The operating environment of this article: windows10 system, javascript 1.8.5, thinkpad t480 computer.
Event handlers are divided into DOM0 level and DOM2 level. If the event is bound by onclick, it can be canceled by the following method:
btn.onclick=null;//删除事件处理程序
If you use the addEventListener() method to add an event, you can use When removeEventListener() removes an event, two points need to be noted:
1. The third parameter of removeEventListener() must be consistent with the third parameter of the addEventListener() method.
2. Anonymous functions added through the addEventListener() method cannot be removed.
btn.aaddEventListener('click',function(){alert(1);},false); btn.removeEventListener('click',function(){alert(1);},false);//没有用!
aaddEventListener and removeEventListener seem to pass in the same parameters, but in fact the second parameter of removeEventListener and the second parameter of aaddEventListener are completely different functions!
You must do this if you want to move out
var fn=function(){ alert(1); }; btn.aaddEventListener('click',fn,false); btn.removeEventListener('click',fn,false);//有效
Recommended learning: javascript video tutorial
The above is the detailed content of javascript how to uncheck event. For more information, please follow other related articles on the PHP Chinese website!