javascript - There is an img tag in a div. Why do I bind events to the div and when printing the clicked object, sometimes it is the img object instead of the div object?
迷茫
迷茫 2017-06-12 09:29:01
0
4
694

When the picture is clicked, the function is also triggered, but I did not bind it to the img. .

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(4)
给我你的怀抱

Use event.currentTarget, event.target returns the element that triggered the event, and event.currentTarget returns the element that bound the event

世界只因有你

Please show how the chooseIcon() method is written.

黄舟

It should be img in p. You can click on the picture to trigger the event. You can print it and it will come out

女神的闺蜜爱上我

Because there is an event bubbling mechanism, when you click img, the binding event of the parent p will also be triggered.

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