javascript之卸载鼠标事件的代码

2016-02-19 09:33 2 1 收藏

岁数大了,QQ也不闪了,微信也不响了,电话也不来了,但是图老师依旧坚持为大家推荐最精彩的内容,下面为大家精心准备的javascript之卸载鼠标事件的代码,希望大家看完后能赶快学习起来。

【 tulaoshi.com - Web开发 】

//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/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

来源:https://www.tulaoshi.com/n/20160219/1591234.html

延伸阅读
标签: Web开发
 onLoadExecutes JavaScript code when a load event occurs; that is, when the browser finishes loading a window or all frames within a FRAMESET tag. Navigator 2.0 Navigator 3.0: event handler of Image   语法onLoad="handlerText"参数   描述Use the onLoad event handler within either the BOD...
标签: Web开发
1、基本概念 JavaScript 是基于对象(object-based)的语言。这与Java不同,Java是面向对象的语言。而基于对象的基本特征,就是采用事件驱动(event-driven)。它是在用形界面的环境下,使得一切输入变化简单化。通常鼠标或热键的动作我们称之为事件(Event),而由鼠标或热键引发的一连串程序的动作,称之为事件驱动(Event Driver)。...
标签: Web开发
events=[];for(o in document)if(/^on/.test(o))events.push(o)  这里输入代码内容  0 [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
标签: Web开发
在很多语言的学习中,“事件”都是一个比较难理解,但是又是一个很重要的概念。JavaScript中的事件处理也是一样,正因为有了事件处理,才会出现Ajax拖动的效果。本文就讨论一下JavaScript中的事件处理,读过之后,您就会知道,很多Ajax框架实现拖动效果的原理了。 一、 IE Event对象 (一)IE Event对象的主要属性和方法 在IE中有一个专门负...
标签: Web开发
事件处理概述  事件处理是对象化编程的一个很重要的环节,没有了事件处理,程序就会变得很死,缺乏灵活性。事件处理的过程可以这样表示:发生事件 - 启动事件处理程序 - 事件处理程序作出反应。其中,要使事件处理程序能够启动,必须先告诉对象,如果发生了什么事情,要启动什么处理程序,否则这个流程就不能进行...

经验教程

752

收藏

54
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部