我的代码:
HTML
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox.js"></script>
<div id="map" style="width:500px; height:500px"></div>
<div id="mappa-infowindow" style="display:none;">
<div style="background-color:#ffffff;">
<span style="cursor:pointer;" class="pulsanteProva">Click</span>
</div>
</div>
jQuery/地图
$("body").on("click", ".pulsanteProva", function () {
alert("clicked");
});
$(window).load(function () {
var templateFinestra = $('#mappa-infowindow');
var infoWindowOptions = {
content: templateFinestra.html(),
pixelOffset: new google.maps.Size(-87, -88)
};
var infowindow = new InfoBox(infoWindowOptions);
var latlng = new google.maps.LatLng(42.745334,12.738430);
var options = { zoom: 12, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP };
var map = new google.maps.Map(document.getElementById('map'), options);
var marker = new google.maps.Marker({ position: latlng, map: map, title: 'Example' });
markerClick = function () {
infowindow.setContent(templateFinestra.html());
infowindow.open(map, marker);
};
google.maps.event.addListener(marker, 'click', markerClick);
});
当我单击标记而不是跨度Click
时,它必须向我显示警报,但实际上它不起作用。似乎没有附加处理程序?为什么?
将函数放入on
函数内部并从地图父级附加它都不起作用http://jsfiddle.net/arEWv/9/