在我的应用程序中,用户在单击 map 时创建标记。所以代码如下:
function placeMarker(map, location) {
var marker = new google.maps.Marker({
position: location,
map: map
//other...
var infowindow = new google.maps.InfoWindow({
content: ballon.get(0)
});
ballon.find("#delete-btn").click(function(){
infowindow.close();
$mapPreview.data("markers")[id].marker.setMap(null);
delete $this.data("markers")[id];
});
});
"#delete-btn"
位于 infowindow
内。问题是,当用户单击“#delete-btn”时,他还会在 map 上创建新标记。我怎样才能避免这种情况?
最佳答案
baloon.find("#delete-btn").click(function(e){
e.stopPropagation();
将事件变量传递给点击函数(e)
,然后使用e.stopPropagation()
停止事件传播
这将阻止事件通过 DOM 冒泡并被各种其他监听器(例如 map 上的监听器)拾取。
关于javascript - 谷歌地图 API : force map to do not handle click inside infobox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11945951/