我需要知道何时单击 Map Data 链接(见图 1,右下角)。当地图数据窗口打开时,它被覆盖的元素隐藏(图 2)。所以我必须在收到打开窗口的触发器时隐藏它们,并在关闭时重新显示它们。
我试图捕捉地图画布下的所有点击事件,如下所示,但是当我点击“地图数据”时我没有被触发
$("googleMapCanvas a").click(function() {
alert("link under map clicked");
});
有任何想法吗?
图 1
图 2
更新
这是克里斯蒂安回答后我的功能代码
<div id="googleMapCanvas">
</div>
<div id="currentLocationBubbleContainer">
...
</div>
<script>
$("#googleMapCanvas").on('click', 'a', function(event) {
var host = event.target.host;
var isGoogleExternalLink = false;
if (host != null && host.search(".google.") != -1 ){
isGoogleExternalLink = true;
}
//It's not enough to check the innerHTML because it's content varies
//depending on the device langage, so in stead I check if it is not
//a click on the google logo, or on the terms of use which are external links
if (event.target.innerHTML == "Map Data" || ! isGoogleExternalLink ){
hideCurrentLocationBubble();
}
});
//Close button of Map Data window
$("#googleMapCanvas").on('click', 'img', function(event) {
if (event.target.src == "https://maps.gstatic.com/mapfiles/transparent.png"){
showCurrentLocationBubble();
}
});
</script>