When debugging the function module, I found that the div added in the infowindow could not be bound to the event using any method. Depressing! I searched many methods on the Internet to no avail.
After thinking about it, I checked the official API and found that there is a domready event in the Events under google.maps.InfoWindow
Official explanation:
This event is fired when the containing the InfoWindow's content is attached to the DOM. You may wish to monitor this event if you are building out your info window content dynamically.
I understand that the general meaning is InfoWindow The callback function after the dynamically added Dom element is completed.
JS is a single-threaded engine. Events can only be bound after the DOM is created. This should be very simple to understand!
Looking at the js code written by a colleague, there are a lot of delays such as setTimeout. I guess I didn’t understand the smooth execution of the script. I thought it would be executed after a delay of a few seconds. In fact, the problem is huge. Which scripts should be executed first and which ones should be executed later are all in order.
google.maps.event.addDomListener The code for listening to Dom element events provided by googleMap
: