2
可能重复:
Javascript closure inside loops - simple practical example
Please explain the use of JavaScript closures in loops如何将参数传递给addEventListener侦听器函数?
for (var i = 0; i < pois.length; i++) {
pois[i].marker.addEventListener('dblclick', function (data) {
var infoWindow = new BMap.InfoWindow(pois[i].address, opts);
map.openInfoWindow(infoWindow, map.getCenter());
})
}
这是我的代码。
显然有在这里错误
新BMap.InfoWindow(POI的[I]。地址,选择采用);
如何在pois [i] .marker监听器函数中使用pois [i] .address?
你正在使用哪个版本,什么是'pois []'代表什么? –