Onclick 在infowindow中单击一个按钮会导致MapClick在google maps api v3上注册

Onclick 在infowindow中单击一个按钮会导致MapClick在google maps api v3上注册,onclick,maps,infowindow,Onclick,Maps,Infowindow,我有一个信息窗口,它有一个“擦除条目”按钮,单击该按钮时,会删除标记并关闭信息窗口。 当我点击“擦除条目”按钮时,它会移除标记并关闭信息窗口,但它也会再次点击地图,我不知道为什么,这让我发疯 以前有人碰到过这个问题吗? 我对javascript很在行,所以任何关于实现的建议都很好。感谢 下面是我正在做的工作的伪代码/摘要: //global variable to keep track of which was the last marker clicked va

我有一个信息窗口,它有一个“擦除条目”按钮,单击该按钮时,会删除标记并关闭信息窗口。 当我点击“擦除条目”按钮时,它会移除标记并关闭信息窗口,但它也会再次点击地图,我不知道为什么,这让我发疯

以前有人碰到过这个问题吗? 我对javascript很在行,所以任何关于实现的建议都很好。感谢 下面是我正在做的工作的伪代码/摘要:

        //global variable to keep track of which was the last marker clicked
        var lastMarkerJustClicked;

        function load(){
            //create the map and everything, add the following listener
            google.maps.event.addListener(map, 'click', function (event) {
                //firebug has been telling me that after i click "erase entry" and my marker is removed and my infowindow closes, i end up here
                makeParticularMarker(event.latLng);
            });
        }

        function makeParticularMarker(marker_parameter) {
            var markerLocation = //do stuff to get the right marker parameter
            var markerWithLocation = new google.maps.Marker({
                position: markerLocation,
                map: map
            }); 
            var html = "<input type='button' value='Erase Entry' onclick=eraseEntry() />"
            var markerWithInfo = createMarkerWithHTML(markerWithLocation, html);
        }

        function createMarkerWithHTML(markerWithLocation, html) {
            var markerWithInfo = google.maps.event.addListener(markerWithLocation, 'click', function () {
                infoWindow.setContent(html);
                infoWindow.open(map, markerWithLocation)
                lastMarkerJustClicked=markerWithLocation;
            });
        }

        function eraseEntry() {
            infoWindow.close()
            lastMarkerJustClicked.setMap(null);
        }
//用于跟踪上次单击的标记的全局变量
var lastMarkerJustClicked;
函数加载(){
//创建映射和所有内容,添加以下侦听器
google.maps.event.addListener(映射,'click',函数(事件){
//firebug一直告诉我,在我点击“擦除条目”后,我的标记被删除,信息窗口关闭,我就在这里结束了
makeSpecialMarker(event.latLng);
});
}
函数makeSpecificularMarker(marker_参数){
var markerLocation=//执行一些操作以获得正确的标记参数
var markerWithLocation=new google.maps.Marker({
位置:markerLocation,
地图:地图
}); 
var html=“”
var markerWithInfo=createMarkerWithHTML(markerWithLocation,html);
}
函数createMarkerWithHTML(markerWithLocation,html){
var markerWithInfo=google.maps.event.addListener(markerwithilocation,'click',函数(){
setContent(html);
infoWindow.open(地图、标记和位置)
lastMarkerJustClicked=markerWithLocation;
});
}
函数项(){
infoWindow.close()
lastMarkerJustClicked.setMap(空);
}
我在这里找到了答案:

这与传播有关。你可以这样做来阻止它

function doSomething(e)
{
    if (!e) var e = window.event;
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
}
本网站对此给出了更好的解释: