我的代码
<div id='map'></div>
<div id="info"></div>
[...]
var markers1 = new L.MarkerClusterGroup( { showCoverageOnHover: true } );
$.ajax({
type: "GET",
url: "db.php",
success: function (result) {
var JSONobject = JSON.parse(result);
var jnCount = JSONobject.length;
for (var i = 0; i < jnCount; i++) {
var marker = new L.Marker(new L.LatLng(JSONobject[i]["lat"],JSONobject[i]["lng"]),{ icon: myIcon1 });
var id = JSONobject[i]["id"];
var list = "<dl>"
+ "<dt><b>CITTA':</b> " + JSONobject[i]["citta_"] + "</dt>";
marker.on('click', function()
{ {document.getElementById('info').innerHTML = list;} });
markers1.addLayer(marker);
}
map.addLayer(markers1);
}
});
标记 onclick 只显示最后一条记录!我认为问题出在循环中,但我不明白如何解决它。任何想法?
谢谢
尼古拉