任何谷歌地图标记的JavaScript点击事件?

点击任何谷歌地图标记时,我需要发生一些事情。 我使用此链接中的演示作为起点:

http://gmap3.net/examples/tags.html

更新 – 香港专业教育学院尝试了以下内容:

$.each(markers, function(i, marker){ marker.click(function(){ alert('alert'); }); }); $.each(markers, function(i, marker){ $(marker).click(function(){ alert('alert'); }); }); 

更新我已尝试将此中间部分添加到现有代码:

  $.each(markers, function(i, marker){ marker.setMap( checked ? map : null); //added code begins $(marker).click(function(){ alert('dfd'); }); //added code ends }); 

请注意,OP要求使用GMAP3库来执行此操作,该库是一个jQuery插件库,可在Google Maps图层上添加API层。 说Google API是使用google.maps.addListener是绝对正确的,但我认为OP想要使用addMarkers更接近GMAP3示例 ,但是听一下click事件。 考虑到这一点,我修改了GMAP3中的示例并将mouseenter事件更改为click事件并摆脱了mouseleave事件。

对于那些想要进一步玩的人,我创建了一个这个例子的jsFddle 。

这是来源:

          
 google.maps.event.addListener(marker, 'click', function() { }); 

参考: https : //code.google.com/apis/maps/documentation/javascript/events.html#UIEvents

示例: http : //jsfiddle.net/diode/yXQwp/

你的问题确实不需要太多细节,但也许你需要这样的东西:

 $.each(markers, function(i, marker){ marker.click(function(){ //maybe, its $(marker).click console.log(marker); }); }); 

编辑:这个为你工作…

 google.maps.event.addListener(marker, 'click', toggleBounce); 

如果你谷歌确切的行,你得到进一步的指示……祝你好运!