将传单弹出信息添加到特定div

时间:2016-05-31 11:55:32

标签: javascript html leaflet

我想将弹出数据添加到我创建的特定div tab4。我在我的问题中发布了代码。这就是我到目前为止所拥有的。如果我console.log(d.html)我得到了正确的输出,但它还没有显示在我的div中。我想我错过了绑定或推送到tab4 div的内容,但我不确定。

window["mapDataLayer"] = L.geoJson(geojson, {
         onEachFeature: function (feature, layer){
           layer.on({
                click: function showResultsInDiv() {
                    var d = document.getElementById('tab4');
                    d.html = "";
                        for (prop in feature.properties){
                        d.html += prop+": "+feature.properties[prop]+"<br>";
                        }
                    console.log(d.html);
                    // I Think i need a line of code here that pushes it to the 'tab4' div.
                }
            }); }
    }).addTo(map);

1 个答案:

答案 0 :(得分:2)

我修好了,需要使用innerHTML代替html。所以现在这是完整的代码:

window["mapDataLayer"] = L.geoJson(geojson, {
         onEachFeature: function (feature, layer){
           layer.on({
                click: function showResultsInDiv() {
                    var d = document.getElementById('tab4');
                    d.innerHTML = "";
                        for (prop in feature.properties){
                        d.innerHTML += prop+": "+feature.properties[prop]+"<br>";
                        }
                    console.log(d.innerHTML);
                }
            }); }
    }).addTo(map);