Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 动态加载内容时,传单弹出窗口未对齐_Jquery_Css_Popup_Alignment_Leaflet - Fatal编程技术网

Jquery 动态加载内容时,传单弹出窗口未对齐

Jquery 动态加载内容时,传单弹出窗口未对齐,jquery,css,popup,alignment,leaflet,Jquery,Css,Popup,Alignment,Leaflet,在动态加载内容时,我遇到了弹出窗口未对齐的问题,如以下JSFIDLE: 使用传单0.7.2: var new_marker = L.marker([lat, lon]) .bindPopup("<div id='popupcontent'></div>", {maxWidth: 500, maxHeight: 300}) .on('click', function(e){ $.post("updatecontent.

在动态加载内容时,我遇到了弹出窗口未对齐的问题,如以下JSFIDLE:

使用传单0.7.2:

var new_marker = L.marker([lat, lon])
        .bindPopup("<div id='popupcontent'></div>", {maxWidth: 500, maxHeight: 300})
        .on('click', function(e){
            $.post("updatecontent.php", {lat: lat, lon: lon},
            function(data) {
                $('#popupcontent').html(data);
            });
        });

map.addLayer(new_marker, true);
但是当弹出窗口打开时,它会移动


有什么想法吗?谢谢:)

设置好弹出窗口的内容后,您应该将弹出窗口绑定到标记上

var popup = new L.Popup();

marker.addTo(map);

marker.on('click', function(e) { 
    popup.setContent('Hello world');
    marker.bindPopup(popup);
    marker.openPopup();
});

要对齐弹出文本,请执行以下操作

marker.bindPopup('<div id="popupcontent" class="centerClass"></div>');

是的,但这不是动态加载内容。我需要将$.post请求的结果设置到弹出窗口中。只需将setContent、bindpoppup、openPopup放在$.post的回调中即可。
marker.bindPopup('<div id="popupcontent" class="centerClass"></div>');
.centerClass{
  text-align: center;
}