简体   繁体   English

jQuery 对话框未在中心显示

[英]jQuery dialog box not showing in the center

I am having the same issue as i had in this question but now for all browsers.我遇到了与这个问题相同的问题,但现在适用于所有浏览器。

Here is the code:这是代码:

$('form#main').live('submit', function(e) {
        e.preventDefault();
        var $this = this;
        ////console.log('click submit')
        var $div = $('<div>', {
            html: 'Are you sure you want to submit this table?<br/> All undo information will be lost.'
        }).dialog({
            modal: true,
            title: 'Are You Sure?',
            buttons: {
                ok: function() {
                    self.console('clicked ok');
                    $.post($this.action, $($this).serialize() + '&page=' + self.pageOn, function(data) {
                        self.console(data);
                        $('.DEV-time').text("  (File last updated at: " + data.DEV + ")");
                        $('.PROD-time').text("  (File last updated at: " + data.PROD + ")");
                        if(data.ERROR.length > 0){
                            alert(data.ERROR);
                        }
                        self.pageChanged = false;
                        self.origPage = $('#page').clone();
                        self.lastClick = $('#page').clone();
                    }, 'json')
                    $(this).dialog('close');
                },
                cancel: function() {
                    $(this).dialog('close');
                }
            },
            beforeClose: function() {
                $(this).remove();
            }
        })

        $div.dialog('widget').css('margin', '0 auto');

        return false;
    })

In addition to 'margin', you need to give it an explicit css width.除了'margin',你需要给它一个明确的 css 宽度。

I think your problem is that the.dialog() method doesn't know content height before it loads.我认为您的问题是 .dialog() 方法在加载之前不知道内容高度。 Either try defining height in dialog definition, or try this Centering jQuery UI dialog of unknown height - is it possible?尝试在对话框定义中定义高度,或者尝试这个未知高度的 Centering jQuery UI 对话框 - 可能吗?

EDIT: sorry, I didn't see it was about centering it horizontally.编辑:对不起,我没有看到它是关于水平居中的。 If so, you probably need to explicitly set the width of the dialog, or use the same trick as above in the link.如果是这样,您可能需要明确设置对话框的宽度,或者在链接中使用与上面相同的技巧。

REMOVING the:删除

$div.dialog('widget').css('margin', '0 auto');

which was the fix to the last question, fixed it this time这是最后一个问题的修复,这次修复了

have you import/include the position.js?您是否导入/包含 position.js? on your code?在你的代码上?

<script src="jquery.ui.position.js"></script>

it's work for me这对我有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM