javascript - Please tell me, under what circumstances do you need to bind events to each li instead of using event delegation?
漂亮男人
漂亮男人 2017-06-12 09:32:46
0
2
783

See some code that binds events to each li without using event delegation? I don’t know what kind of trial scenario it is.

漂亮男人
漂亮男人

reply all(2)
漂亮男人

Code that needs to be refactored~~~

But if there is such a code, it is recommended that you consult with the business first to find out the ins and outs before making a decision.

If nothing else happens,
Even if the events of each li are different, I will add different styles, and then do event delegation on ul, and will not bind them one by one on li.

仅有的幸福

There are many examples online.

Event delegation can reduce the pressure of event listening.
Secondly, when you load data asynchronously with event delegation, when the returned data is generated into a dom node, if the dom node happens to have an event, you need to bind the event. If you use event delegation, you only need to bubble up to the dom node. No need to bind the event again.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template