如何在弹出窗口中插入新行文本


9

我正在使用Leaflet Marker Cluster,并且我需要在弹出窗口中显示五行。但是,当我写这篇文章时,它们都在同一行。有人可以帮助我成为另一个人吗?

var a = addressPoints[i];
            var title = a[2];
            var univ = a[3];
            var direct = a[4];
            var city = a[5];
            var state = a[6];
            var marker = new L.Marker(new L.LatLng(a[0], a[1]), { title: title } );
            marker.bindPopup("Student: " + title + "University: " + univ + "Direction: " + direct + "City: " + city + "State: " + state);
            markers.addLayer(marker);
        }

    map.addLayer(markers);

Answers:


17

Leaflet文档所述,Marker#bindPopup将HTML字符串作为第一个参数。

如果希望各行显示在不同的行上,则需要添加适当的HTML标记。在您的情况下,定义列表似乎最相关。

因此:

var list = "<dl><dt>Student</dt>"
           + "<dd>" + title + "</dd>"
           + "<dt>University</dt>"
           + "<dd>" + univ + "</dd>"
           + 

marker.bindPopup(list);
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.