方法:1、使用“对象名.onclick=null”语句;2、使用“对象名.removeeventlistener(type,function(){},false)”语句;3、使用“对象.detachevent(类型,名称)”语句。

本教程操作环境:windows7系统、javascript1.8.5版、Dell G3电脑。
封装一个兼容性事件绑定方法 应需求有时候事件绑定触发后就要接触事件。
解除事件绑定方法:
1、onclick解除
element.onclick = false/''/null
实例
<p></p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/c1c2c2ed740f" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">Java免费学习笔记(深入)</a></a>”;</p>
var p = document.getElementByTagName("p")[0];
p.onclick = function () {
console.log("a");
p.onclick = null;
}2、解除addEventListener(type,function(){},false),
使用remove解除
解除addEventListener(type,function(){},false),必须事件类型、函数、false一一对应
错误的解除方式
var p = document.getElementByTagName("p");
p.addEventListener('click',function(){
console.log("a");
},false)
p.removeEventListener(type,(function(){console.log("a");}),false)这种情况是解除不了的
正确的解除方式
function test(){
console.log("a");
}
p.addEventListener('click',test,false);
p.removeEventListener('click',test,false);3、解除attachEvent('on'+ type,function(){}),用 detachEvent('on'+type,function(){})解除
function test(){}
obj.attachEvent('on'+ type,test);
obj.detachEvent('on'+type,test)【推荐学习:javascript高级教程】











