JS, we can add a listener event to a DOM object, the function isAddEventListener ("click", Function () {},true);It is easy to understand that the first parameter is the event type, such as Click, Touch (Touchstart),The second argument is an event function,For example, I add an alert function to a button.Window.onload=function () {document.getElementById ("Hello"). AddEventListener ("onkeydown", function () {Alert ("Hello");});}So what's the third para
UseCapture and addEventListener are the three parameters of addeventlistener.
AddEventListener has three parameters: the first parameter indicates the event name (not including on, such as "click"); the second parameter indicates the function for Receiving Event processing; the third parameter is useCapture, this article will explain it.
Copy codeThe Code is as f
Mozilla:
How to Use addeventlistener:
Target. addeventlistener (type, listener, usecapture );
Target: Document node, document, window, or XMLHttpRequest.Type: String, event name, excluding "on", such as "click", "Mouseover", and "keydown.Listener: implements the eventlistener interface or functions in JavaScript.Usecapture: whether to use capture. Generally
This article summarizes the usage of addEventListener () and removeEventListener (). For more information, see.
AddEventListener () and removeEventListener () are used to process specified and deleted event handlers. All DOM nodes contain these two methods, and both of them accept three parameters: the time name to be processed, the function used as the event handler, and a Boolean value. The Boolean parame
In Mozilla:How to use AddEventListener:
Target.addeventlistener (type, listener, usecapture);
Target: Documentation node, document, window, or XMLHttpRequest.
Type: String, event name, excluding "on", such as "click", "MouseOver", "KeyDown", and so on.
Listener: Implements a EventListener interface or a function in JavaScript.
Usecapture: Use capture, generally false. For example: document.getElementById
AddEventListener () and removeEventListener () parsing, removeeventlistener
AddEventListener () and removeEventListener () are used to process specified and deleted event handlers.All DOM nodes contain these two methods, and both of them accept three parameters: the name of the event to be processed, the function used as the event handler, and a Boolean value.
The Boolean parameter is true, indicating that
");
Object.attachevent (event,function);
Btn1obj.attachevent ("onclick", method1);
Btn1obj.attachevent ("onclick", method2);
Btn1obj.attachevent ("onclick", method3);
The order of execution is method3->method2->method1
=======================================================
In Mozilla:
How to use AddEventListener
Target.addeventlistener (type,listener,usecapture);
Target: Documentation node, document, window, or XMLHttpRequest.
Ty
AddEventListener () and RemoveEventListener () are used to handle the specified and deleted event handler actions. Both methods are included in all DOM nodes, and they all accept 3 parameters: The time name to process, the function as the event handler, and a Boolean value. The last Boolean parameter is true, which means that the event handler is invoked during the capture phase, or false, which indicates t
(event,function,capture/bubble);Windows IE has the following format:DetachEvent (event,function);Target.addeventlistener (type, listener, usecapture);Target documentation node, document, window, or XMLHttpRequest.The type string, the event name, does not contain "on", such as "click", "MouseOver", "KeyDown", and so on.Listener implements a EventListener interface or a function in JavaScript.Usecapture whether to use snapping, see the next event strea
EventListener interface or a function in JavaScript. For example: document.getElementById ("TXT"). attachevent ("onclick", function (event) {alert (event.keycode);});Internet Explorer and IE also support the removal of the specified event, the purpose is to remove the set of events, the format is as follows:The format of the consortium:RemoveEventListener (event,function,capture/bubble);Windows IE has the following format:DetachEvent (event,function)
AddEventListener () and RemoveEventListener () are used to process the specified and delete event handler actions. Both methods are included in all DOM nodes, and they all accept 3 parameters: the name of the event to be processed, the function that is the event handler, and a Boolean value. Most of this Boolean parameter is true, which means that the event handler is called during the capture phase, or fal
, this Microsoft private method is not supported by Firefox and other browsers. Fortunately, they all support the W3C standard addEventListener method.View source
1 // element. addEventListener (type, listener, useCapture );2 btn1Obj. addEventListener ("click", method1, false );3 btn1Obj. addEventListener ("click", met
JS Advanced Programming Note-addeventlistener () and RemoveEventListener (), event cancellation and bindingAddEventListener () and RemoveEventListener () are used to process the specified and delete event handler actions. Both methods are included in all DOM nodes, and they all accept 3 parameters: the name of the event to be processed, the function that is the event handler, and a Boolean value. Most of this Boolean parameter is true, which means tha
DOM: element. addeventlistener
From MDC
«Gecko DOM reference
Contents [Hide]
1 Summary
2 Syntax
3 Example
4 Notes
4.1 Why use addeventlistener?
4.2 Adding a listener during event dispatch
4.3 Multiple identical Event Listeners
4.4 The value of this within the Handler
4.5 Internet Explorer
Generally, we add events in JS.View source
1 obj. onclick = methodThis event binding method is compatible with mainstream browsers. But what if the same event is added to an element multiple times?View source
1 obj. onclick = method1;2 obj. onclick = method2;3 obj. onclick = method3;If this is the case, only the last Bound event will be executed. In this case, we will not be able to use the onclick statement, in IE, we can use the attachEvent method.View source
1 // object. attachEvent (event, f
You may be familiar with IE's attachevent method. Now let's talk about the usage of Firefox's addeventlistener.
The addeventlistener has three parameters. Syntax:
Element. addeventlistener (type, listener, usecapture)
Below is a detailed explanation
Element is the object to bind the function.
Type is the event name. Note that you should change "o
AddEventListener () and RemoveEventListener () are used to process the specified and delete event handler actions. Both methods are included in all DOM nodes, and they all accept 3 parameters: the name of the event to be processed, the function that is the event handler, and a Boolean value. Most of this Boolean parameter is true, which means that the event handler is called during the capture phase, or fal
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.