javascript之卸载鼠标事件的代码
岁数大了,QQ也不闪了,微信也不响了,电话也不来了,但是图老师依旧坚持为大家推荐最精彩的内容,下面为大家精心准备的javascript之卸载鼠标事件的代码,希望大家看完后能赶快学习起来。
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/buttonbr
button onclick=delEvent(document,"onclick",test1)del1/buttonbr
button onclick=addEvent(document,"onclick",test2)add2/buttonbr
button onclick=delEvent(document,"onclick",test2)del2/buttonbr
script
function test1(){
alert("test1")
}
function test2(){
alert("test2")
}
document.onclick=function(){
alert(1)
}
/script
/BODY
/HTML


