Google Map V3 綁定氣泡視窗(infowindow)Dom事件實現代碼

來源:互聯網
上載者:User

在調試功能模組時候,發現怎麼用什麼方法都無法在infowindow裡面添加的div進行綁定事件處理。鬱悶啊!上網搜了好多方法也沒用,
後來想想還是查了一下官方的API,發現了google.maps.InfoWindow下面的Events裡面有個domready事件

官方解釋
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.
本人理解大概的意思就是InfoWindow裡面動態添加的Dom元素完成後的回呼函數。
js是個單線程的引擎,只有等到DOM建立完成之後才能綁定事件,這樣理解起來應該很簡單了吧!
看同事寫的js代碼,裡面好多setTimeout之類的延遲 估計沒弄清楚指令碼執行的順利 覺的延遲幾秒就行執行,其實問題很大。哪些指令碼要先執行,哪些要後執行 都是有順序的。
google.maps.event.addDomListener googleMap 提供的監聽Dom元素的事件

上代碼

複製代碼 代碼如下:
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();});
});

官方API:https://developers.google.com/maps/documentation/javascript/3.exp/reference?hl=zh-cn

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.