1

我在这里有一个网站有一个网站...

我没有创建小提琴,因为我不确定如何使用 ajax 复制该问题。

当网站加载时,会自动弹出一个 ajax 请求。

它偏离中心,当我在那里添加位置标志时,模式根本不会出现。我没有收到任何语法错误,所以我不确定出了什么问题。

使用此代码,弹出窗口打开(但偏离中心)......

$(document).ready( function() {
    jQuery('#compliance').load('jquery-ajax.html').dialog();
});

当我添加位置标志时,它根本不显示......

$(document).ready( function() {
    jQuery('#compliance').load('jquery-ajax.html').dialog({
        position: {my: "center top", at:"center top", of: window },
    });
});

编辑-

这就是最终奏效的...

    $(document).ready( function() {
        jQuery('#compliance').load('jquery-ajax.html').dialog({
        resizable: false,
        modal: true,
        width: 750,
        show: 'fade',
        hide: 'fade',
        position: {my: "center top", at:"center top", of: window }
        });
});
4

2 回答 2

1

我相信您的问题与将 ajax 加载到模式框中有关。这可能会导致内容大小问题等。您可以尝试添加

jQuery('#compliance').load('jquery-ajax.html').dialog({
    resizable: false,
    modal: true,
    width:'auto'
});

同样为将来参考,您不应该jQuery在对元素进行操作时使用。您可以使用该$标志。如果这不起作用,那么您的 DOM 中 javascript 的加载顺序可能存在问题

于 2013-09-19T23:08:24.990 回答
1

A short timeout re-positioning the dialog did the trick for me. All other attempts failed.

setTimeout(function(){
    $("#dialog-selector").dialog('option', 'position', 'center');
}, 50); 
于 2017-11-12T16:52:41.460 回答