【问题标题】:info window button click not calling a function信息窗口按钮单击不调用函数
【发布时间】:2016-12-16 11:46:15
【问题描述】:

我想在谷歌地图标记的信息窗口上做按钮点击事件信息窗口。以下是我的代码,但点击事件不调用函数

function createmarker(map, marker) {
   var request = $http({
    method: "post",
    url: "example.com",
    data: {
     email: localStorage.getItem("email_id")
    },
    headers: {
     'Content-Type': 'application/x-www-form-urlencoded'
    }
   });

   request.success(function(response) {
    for (i = 0; i < response.length; i++) {

     marker = new google.maps.Marker({
      position: new google.maps.LatLng(response[i].curlat, response[i].curlng),
      map: map,
      animation: google.maps.Animation.DROP
     });

     google.maps.event.addListener(marker, 'click', (function(marker, i) {
      return function() {
       var infowindow = new google.maps.InfoWindow({
        content: "<input type='button' value='View' onclick='joinFunction()'>" + "<input type='button' value='Join' onclick='alert(\"infoWindow\")'>"
       });
       // infowindow.setContent( '<button onclick="viewFunction()">View</button>');
       infowindow.open(map, marker);
      }
     })(marker, i));
    } //for loop close

   }); //http close
  }; //create marker close
  function joinFunction() {

  }

【问题讨论】:

  • 将事件监听器放在你的函数之外

标签: javascript jquery html google-maps-api-3 ionic-framework


【解决方案1】:

您可以设置使用:

 infowindow.setContent('<input type="button" value="View" onclick="joinFunction()"><input type="button" value="Join" onclick="alert(\"infoWindow\")">');

会有用的

【讨论】:

  • 显示警报消息但未调用 joinFunction
  • 它调用join函数。你把函数放在哪里了?
猜你喜欢
  • 2016-02-23
  • 2019-06-06
  • 2016-08-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-08
  • 1970-01-01
  • 2015-02-11
相关资源
最近更新 更多