When debugging the function module, I found that no method can be used to bind the div added in infowindow for event processing. Depressed! It is useless to search the Internet for many methods,
Later, I checked the official API and found a domready event in Events under google. maps. InfoWindow.
Official explanation:
This event is fired when the ining 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.
What I understand is the callback function after the Dom elements dynamically added in InfoWindow are completed.
Js is a single-threaded engine. events can be bound only after DOM is created. It should be easy to understand!
Looking at the js code written by my colleagues, the latency of many setTimeout operations is estimated to be several seconds before the execution of the script is smooth. In fact, the problem is very high. Which scripts need to be executed first and which need to be executed later are ordered.
Google. maps. event. addDomListener events provided by googleMap to listen to Dom elements
Code on:
Copy codeThe Code is as follows:
Google. maps. event. addListener (infowindow, "domready", function (){
Var Cancel = document. getElementById ("Cancel ");
Var OK = document. getElementById ("OK ");
Google. maps. event. addDomListener (Cancel, "click", function () {infowindow. close ();});
Google. maps. event. addDomListener (OK, "click", function () {infowindow. close ();});
});
Official API: https://developers.google.com/maps/documentation/javascript/3.exp/reference? Hl = zh-cn