在使用百度地图API的时候,发现循环输出提示框的时候,每一个提示框都显示一样的内容.解决方法如下

for (var i = 0; i < result.Data.length; i++) {
  (function (x) {//关键加这个标记
    var infoWindow = new BMap.InfoWindow(GetContent(result.Data[i]), opts); 
    var marker = new BMap.Marker(new BMap.Point(result.Data[i].LONGITUDE, result.Data[i].LATITUDE))
    marker.addEventListener("click", function () {
    this.openInfoWindow(infoWindow);
    document.getElementById('imgDemo').onload = function () {
      infoWindow.redraw();
      }
    });
    markers.push(marker);
  })(i);
}

 

 其他的大家忽略好了,我标记的就是解决方法.(来自网络)

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-02
  • 2021-10-27
  • 2022-12-23
  • 2021-04-28
  • 2021-09-12
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案