React event handling and event handling native JS

1. events trigger a call and this point

1. native JS

Event trigger a call in three ways:

1) on [event] event, triggered manually ❗️ ON [Event] event is method on the Window object .

2) on [event] event, by htmlElement.click () analog trigger

3) addEventListener listening to events, triggered manually

this point

1) If onevent this event will be passed as parameters to obtain the transfer of the DOM object. You can get the current DOM using this method.

2) in this direct access method, this point where the scope of the current function. Or call the function of the object.

<body> 
    <INPUT type = "CheckBox" ID = "the root" the onmouseover = "toclick (the this, Event)" the onclick = "the Add ()" /> 
    <Button the onclick = "A.test (the this)"> the Test </ Button> 
    <Script> function toclick (argThis, E) { 
            the console.log (E); // Event objects; parameters must manually transfer 
            the console.log (argThis); // pass over this point DOM elements by this method calls itself   
            const = rootEle argThis; // equal document.getElementById ( 'the root'); 
            rootEle.click (); // there is no parameter, but triggered         }
         function the Add (Arg) { 
            the console.log (Arg);// undefined description of the event you want to get event and other parameters necessary to pass parameters
        

            the console.log ( the this ); // window mouseover either inside or directly triggered by the Trigger rootEle corresponds directly run the Add () 
        } 
        const A = { 
            Test (argThis) { 
                the console.log (argThis); // DOM elements of 
                the console.log ( the this ); // the this target point A? 
            } 
        } 
        const rootEle = document.getElementById ( "the root" ); 
        rootEle.addEventListener ( 'the Click', function () { 
            the console.log ( 'the listen === ', the this ); //DOM element; call directed listener object 
        })
      </ Script> 
</ body>

 

Guess you like

Origin www.cnblogs.com/lyraLee/p/11577511.html