如何在几秒钟后单击标记n启用后禁用单击事件

时间:2016-06-30 05:03:10

标签: javascript

如何在单击后禁用标记点击事件,并在几秒后启用 这是我的代码

$(function () {
    $.ajax({
        type: "POST",
        url: "GetDropDown",
        data: '{}',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (r) {
            alert("success");
            $.each(r.d, function () {
                alert("error");
            });
        }
    });
});

由于

2 个答案:

答案 0 :(得分:0)

您没有附加HTML代码,所以我无法回答您如何禁用按钮本身,但是有一个代码可以防止逻辑被执行:

 function bindInfoWindow(marker, map, infoWindow, description) {

  if (bindInfoWindow.prototype.Enable === undefined || bindInfoWindow.prototype.Enable==true){
      bindInfoWindow.prototype.Enable =false;
      setTimeout(function enableFunc(){
           bindInfoWindow.prototype.Enable =true;
      }, 3000);

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

         var geocoder =  new google.maps.Geocoder();

         geocoder.geocode({ 'latLng': description }, function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                if (results[1]) {
                   var location1=results[1].formatted_address;    
         infoWindow.setContent('Location:'+location1+'<br>');      // set content to marker at click event


                }
            }
        });
     infoWindow.open(map, marker);    

  });
}
 } 

答案 1 :(得分:0)

使用settimeout功能在您的点击事件功能设置时间点击后等待多长时间。修改了你的代码

function bindInfoWindow(marker, map, infoWindow, description) {

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

            setTimeout(function(){
                var geocoder =  new google.maps.Geocoder();

                     geocoder.geocode({ 'latLng': description }, function (results, status) {
                        if (status == google.maps.GeocoderStatus.OK) {
                            if (results[1]) {
                               var location1=results[1].formatted_address;    
                     infoWindow.setContent('Location:'+location1+'<br>');      // set content to marker at click event
                            }
                        }
                    });
                 infoWindow.open(map, marker);  
           }, 3000); // set time how long waiting
      });
 }

希望它有效