javascript之卸載鼠標(biāo)事件的代碼
更新時(shí)間:2007年05月14日 00:00:00 作者:
//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>
<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>
您可能感興趣的文章:
- JavaScript事件類型中焦點(diǎn)、鼠標(biāo)和滾輪事件詳解
- JavaScript事件類型中UI事件詳解
- js控制鼠標(biāo)事件移動(dòng)及移出效果顯示
- javascript簡(jiǎn)單拖拽實(shí)現(xiàn)代碼(鼠標(biāo)事件 mousedown mousemove mouseup)
- JS鼠標(biāo)事件大全 推薦收藏
- JavaScript Event學(xué)習(xí)第九章 鼠標(biāo)事件
- javascript 鼠標(biāo)事件總結(jié)
- JavaScript事件學(xué)習(xí)小結(jié)(五)js中事件類型之鼠標(biāo)事件
相關(guān)文章
javascript實(shí)現(xiàn)仿銀行密碼輸入框效果的代碼
這篇文章通過實(shí)例代碼給大家介紹了javascript實(shí)現(xiàn)仿銀行密碼輸入框效果,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2007-12-12mock.js模擬數(shù)據(jù)的實(shí)現(xiàn)
在沒有后端提供數(shù)據(jù)的情況下,前端人員在自己寫demo或者練手項(xiàng)目的時(shí)候可以使用mock.js來模擬數(shù)據(jù),本文主要介紹了mock.js模擬數(shù)據(jù)的實(shí)現(xiàn),感興趣的可以了解一下2023-11-11axios實(shí)現(xiàn)簡(jiǎn)單文件上傳功能
這篇文章主要為大家詳細(xì)介紹了axios實(shí)現(xiàn)簡(jiǎn)單文件上傳功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-09-09js插件實(shí)現(xiàn)圖片滑動(dòng)驗(yàn)證碼
這篇文章主要為大家詳細(xì)介紹了js插件實(shí)現(xiàn)圖片滑動(dòng)驗(yàn)證碼,滑動(dòng)模塊,實(shí)現(xiàn)驗(yàn)證功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10