javascript之卸载鼠标事件的代码

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

javascript之卸载鼠标事件的代码

  2020-05-12 我要评论
//by xmg
<script>
function addEvent(obj,eventName,eventFunc){
 if(obj.attachEvent) {
 obj.attachEvent(eventName,eventFunc);
 }else if(obj.addEventListener){
 eventName = eventName.toString().replace(/on(.*)/i,'$1');
 obj.addEventListener(eventName,eventFunc,true);
 }
}
function delEvent(obj,eventName,eventFunc){
 if(obj.detachEvent)
 obj.detachEvent(eventName,eventFunc)
 else if(obj.removeEventListener){
 eventName = eventName.toString().replace(/on(.*)/i,'$1');
 obj.removeEventListener(eventName,eventFunc,true);
 }
}
</script>
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<button onclick=addEvent(document,"onclick",test1)>add1</button><br>
<button onclick=delEvent(document,"onclick",test1)>del1</button><br>
<button onclick=addEvent(document,"onclick",test2)>add2</button><br>
<button onclick=delEvent(document,"onclick",test2)>del2</button><br>
<script>
function test1(){
 alert("test1")
}
function test2(){
 alert("test2")
}
document.onclick=function(){
 alert(1)
}
</script>
</BODY>
</HTML>

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们