Add an event html dom node mass participation

Dom node added event method:

document.getElementById("myBtn").addEventListener("click", function(){
    document.getElementById("demo").innerHTML = "Hello World";
});

 

grammar:

element.addEventListener(eventfunctionuseCapture)

 

Parameter Value

 

parameter description
event have to. String that specifies the name of the event.

Note:  Do not use the "on" prefix. For example, use "click", instead of "onclick".

Tip:  All HTML DOM events, you can check out our full  HTML DOM Event Object Reference Manual .
function have to. Specify the function that executes when the event is triggered.

When the event object as the first argument passed to the function. Type of event object depends on the particular event. For example, "click" events were MouseEvent (mouse event) object.
useCapture Optional. Boolean value that specifies whether the event in the capture or bubbling phase.

Possible values:
  • true - in the event handler to perform the capture phase
  • false- false- default. Event handler execution in the bubbling stage

 

Event event delivery parameters

When passing a parameter value, use function calls with arguments "anonymous function":

E.g:

let scope = ‘123’;
this.dom.addEventListener('mousedown', function (){
scope.onMouseDown(event,scope);
},
false);

 

Guess you like

Origin www.cnblogs.com/minnong/p/11927237.html