-1

可能重复:
运行一次后如何“禁用”javascript函数

我有两个按钮,单击它们时,运行以下两个功能之一:

 function addlaunchMark() { 
        google.maps.event.addListener(map, "click", function(event) {
          marker = new google.maps.Marker({
          position: event.latLng,
             map: map     
        });
        infowindow.open(map, marker);
        google.maps.event.addListener(infowindow, "closeclick", function() {
        marker.setMap(null);
            });
        });
    };


  function addfishingMark() {       
     google.maps.event.addListener(map, "click", function(event) {
         marker = new google.maps.Marker({
            position: event.latLng,
            map: map
           });
    fishinfowindow.open(map, marker);
    google.maps.event.addListener(fishinfowindow, "closeclick", function() {
    marker.setMap(null);
        });
    });
};

因此,当有人单击其中一个按钮时,会发生这种情况,它会打开该功能下的动作侦听器。如果您单击另一个按钮,则您已经单击的按钮仍然存在的问题。因此,当您再次单击时,您将获得两个标记和两个 infoWindows。单击另一个按钮后禁用功能或活动侦听器的最简单方法是什么?

4

1 回答 1

0

I think in that case:

 addListenerOnce(instance:Object, eventName:string, handler:Function)

would work

More on: https://developers.google.com/maps/documentation/javascript/reference#event

于 2012-10-28T23:29:29.003 回答