这是我的代码:
window.onload = function(){
var mapOptions = {
zoom: 8,
center: new google.maps.LatLng(5.311005375262571, 100.44538021087646)
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
var marker = new google.maps.Marker({
position: new google.maps.LatLng(5.311005375262571, 100.44538021087646),
map: map
});
var infoWindowContent = '<div><p id="center12" >pop up hi</p></div>'
var infowindow = new google.maps.InfoWindow({
content: infoWindowContent
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
var mapCenter = document.getElementById("center12");
mapCenter.onclick = function(){
alert("hi");
}
});
}
我希望浏览器能够在我点击文字时提醒你,但是它显然不起作用,为什么???
答案 0 :(得分:1)
click
- domready
- infowindow
事件发生时分配 google.maps.event.addListener(infowindow,'domready',function(){
google.maps.event.addDomListener(document.getElementById("center12"),
'click',
function(){
alert('hi');
});
});
- 侦听器(此时将用于显示信息窗口的元素已注入文档) :
{{1}}