current position:Home>Relearn JavaScript events

Relearn JavaScript events

2022-01-27 05:47:17 Xiao Zhang II

1.addEventListener Registration events

  There are two syntax for registering events
            1. Some grammar :   
                * grammar : Event source . Event type = Event handler box.onclick = function (){}
                * The biggest feature : Cannot register multiple “ The same name ” event
            
            2.addEventListener() : Used to register multiple “ The same name ”   event
                * grammar :   Event source .addEvenetListener(' Event type ', Event handler )

2.removeEventListener Remove events

 

3. Block default events

Event delegation ( a key )

1. Event Bubbling : When an event of a child element is triggered , All of this child element “ The parent element ” Of “ Events of the same name ” Will trigger in turn  
            * Event bubbling always exists , It's just that no event with the same name has been registered for the parent element before
            * Subelement -> Parent element -> body -> html -> document -> window

2. Event delegation : Register events for the parent element , Delegate child elements to handle
           2.1 The principle of event delegation : Event Bubbling
           2.2 Attention to event delegation : Out of commission this
                this: Event source , Point to parent element
                e.target: Event trigger source , Point to the child element of the delegate that triggers this event

 

copyright notice
author[Xiao Zhang II],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201270547083181.html