网络编程 
首页 > 网络编程 > 浏览文章

javascript之卸载鼠标事件的代码

(编辑:jimmy 日期: 2025/5/11 浏览:3 次 )
//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>
上一篇:User Scripts: Video Download by User Scripts
下一篇:“增强js程序代码的健壮性”之我见大量示例代码
一句话新闻
Windows上运行安卓你用过了吗
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 网站地图 SiteMap