Invoke Event:
Event Object
What is an event object? Events that trigger on the DOM will produce an event object. For example, when the mouse clicks, they will produce such as the type of the click Ah, and that element issued
The DOM event object Type property is used to get the event object, the target property is used to get the event target, and the Stoppropagation () method blocks event bubbling Preventdefault The default behavior of the blocking event
The event object in IE, the Type property, is used to get the event object, the Srcelement property is used to get the event target cancelbubble property is used to prevent event bubbling setting to true is to indicate that blocking false indicates not blocking
The ReturnValue property is used to block when the default behavior of an event is set to False
Compatible with individual browsers cross-browser event processing-------Unified Encapsulation
var eventhandle = {
Element: Elements, type: Click event, handle: Method of implementation
Add handle
Addeventhandle:function (element, type, handler) {
if (Element.addeventlistener) {
Element.addeventlistener (type, handler, false);//---false//represents the bubbling dom2 level
}
else if (element.attachevent) {
Element.attachevent ("On" +type, Handler);
} else {
Element["on" + type] = handler;
}
},
Delete handle event handling does not work
Removeeventhandle:function (element, type, handler) {
if (Element.removeeventlistener) {//Support DOM2-level event handling type is onclick
Element.removeeventlistener (type, handler, false); ---false//represents bubbling
}
else if (element.detachevent) {
Element.detachevent ("On" +type, Handler); Support IE
} else {
Element["on" + type] = null;//dom0 level Event handling traditional Click events
}
},
Get Event object compatible with all browser objects
Getevent:function (event) {
Return event? Event:window.event; What is needed in the low version of IE is window.event
},
Gets whether the event type is clicked or mouse moved
Gettype:function (event) {
return event.type;
},
Gets the current element.
Getelement:function (event) {
return Event.target | | Event.srcelement;
},
Default behavior for blocking events
: function (Event) {
if (Event.preventdefault) {
Event.preventdefault ();
}
else {
Event.returnvalue = false;
}
},
Block event bubbling
Stoppropagation:function (event) {
if (event.stoppropagation) {
Event.stoppropagation ();
}
else {
Event.cancelbubble = true;
}
}
}
JavaScript compatible with individual browser events