3
我試圖選擇一個<div>
使用jquery的$('#divname')
在Google地圖生成的信息框中,當地圖上的任何多個標記點擊時。如何在Google Maps InfoBox中訪問Div?
問題:當我嘗試訪問使用$("#gallery")
的div後點擊標記,即在該標記的點擊事件偵聽器內部沒有任何反應。我嘗試使用console.log($("#gallery").html())
從click監聽器獲取該div中包含的html,並返回null
!我怎樣才能選擇這個div!?
點擊事件監聽器代碼段
// Create Listeners
markers[i]._index = i;
google.maps.event.addListener(markers[i], 'click', function() {
infoboxes[this._index].open(map, markers[this._index]);
infoboxes[this._index].show();
console.log($('#gallery').html());
});
信息框代碼片段
for(i = 0; i < json.length; i++) {
// Place markers on map
var latLng = new google.maps.LatLng(json[i].lat, json[i].lng);
var marker = new google.maps.Marker({
position: latLng,
map: map
});
markers.push(marker);
// Create infowindows
var boxText = '<div id="infobox"> \
<div id="infobox_header_title"> \
<span id="infobox_header_price">$' + json[i].price + '</span> \
<span id="infobox_header_room">' + json[i].bedroom + 'br </span> \
<span id="infobox_header_address">' + json[i].address_1 + '</span> \
</div> \
<div id="gallery"> \
<img src="images/cl/' + json[i].photos[0] + '.jpg" /> \
<img src="images/cl/' + json[i].photos[1] + '.jpg" /> \
</div> \
</div>';
var infoboxOptions = {
content: boxText,
disableAutoPan: false,
maxWidth: 0,
pixelOffset: new google.maps.Size(-140, 0),
zIndex: null,
boxStyle: {
},
closeBoxMargin: "10px 2px 2px 2px",
closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif",
infoBoxClearance: new google.maps.Size(1, 1),
isHidden: true,
pane: "floatPane",
enableEventPropagation: false
};
var infobox = new InfoBox(infoboxOptions);
infoboxes.push(infobox);
//<Click Event Listener code comes in here>