我有多個標記。在按鈕上打開信息框點擊「外部」地圖(谷歌地圖v3)
我使用該代碼的每一標誌點擊後能夠成功地OPENINFO箱(是其設置標記的環內)
for (var i = 0; i < markers.length; i++) {
....
....
....
google.maps.event.addListener(marker, "click", function() {
//alert(this.html);
infowindow.setContent(this.html);
infowindow.open(map, this);
});
}
上面的代碼工作得很好。
但是現在我想讓每個標記的信息框在地圖上點擊的按鈕上打開。我在同一個循環中嘗試了一些東西。
for (var i = 0; i < markers.length; i++) {
....
....
....
var chandu = document.getElementById(i);
google.maps.event.addDomListener(chandu, "click", function(){
infowindow.setContent(this.html);
infowindow.open(map, this);
//alert("Yo");
});
}
和我有HTML按鈕點擊這樣
<a href="#" id="0">0</a>
<a href="#" id="1">1</a>
<a href="#" id="2">2</a>
<a href="#" id="3">3</a>
<a href="#" id="4">4</a>
<a href="#" id="5">5</a>
但這點擊HTML鏈接部分的不woork
+1正是我需要的。 ;-) – 2013-11-07 16:54:14