简体   繁体   English

jQuery UI对话框显示在页面上而不是弹出窗口

[英]JQuery UI Dialog shows on page instead of popup

I have a jqueryUI dialog popup that is showing on the page... and popping up when requested. 我有一个jqueryUI对话框弹出窗口显示在页面上...并在需要时弹出。 Some odd functionality. 一些奇怪的功能。 Anything within the div will show on the page, and the popup will work however be without the contents on the div. div内的所有内容都将显示在页面上,但是弹出窗口将起作用,但是div上没有内容。 I am trying to create the popup before the document is ready. 我正在尝试在文档准备好之前创建弹出窗口。 Here is the code that my object is running, again before document ready. 这是文档准备好之前,我的对象正在运行的代码。

    var edit_div=document.createElement('div');                 
    var me = this;
    $(edit_div).dialog(
        {
            autoOpen: false,
            height: 400,
            width: 600,
            resizable: false,
            modal: true,
            buttons: 
            {
                "Submit": function() 
                {
                    me.submitForm();
                },
                Cancel: function() 
                {
                    $( this ).dialog( "close" );
                }
            },
            close: function() 
            {
            },

        });

The popup works correctly if I move the dialog creation code to a separate function and call that when the document is ready like so: 如果我将对话框创建代码移到一个单独的函数并在文档准备就绪时调用它,则弹出窗口将正常工作,如下所示:

$(document).ready(function()
{
   mfg_table.init();
}

And the init code to create the dialog 和初始化代码创建对话框

   this.init = function()
    {
        //alert('initing');
        var me = this;
        $('#' +this.table_id + this.edit_table_name).dialog(
            {
                autoOpen: false,
                height: 400,
                width: 600,
                resizable: false,
                modal: true,
                buttons: 
                {
                    "Submit": function() 
                    {
                        me.submitForm();
                    },
                    Cancel: function() 
                    {
                        $( this ).dialog( "close" );
                    }
                },
                close: function() 
                {
                },

            });
    }

So why can't I create the dialog on the DOM object before rendering of the page? 那么,为什么不能在呈现页面之前在DOM对象上创建对话框?

Is it possible your script is being called before your jquery.js files are being loaded by the browser? 是否有可能在浏览器加载jquery.js文件之前调用脚本?

Document.ready waits until the page is fully loaded before running your code. Document.ready等到页面完全加载后再运行代码。 The fact that it isn't working correctly without it, implies that the necessary resources aren't being loaded before you try to run your script. 没有它,它将无法正常工作,这意味着在尝试运行脚本之前,没有加载必要的资源。

You may want to try to move your inline script to the very end of your html file, particularly after all your .js and plugin files have been referenced. 您可能希望尝试将内联脚本移到html文件的末尾,尤其是在引用了所有.js和插件文件之后。

I wish I could be more specific, but it's hard to see whats going on without more of the code or a live example. 我希望我可以更具体一些,但是如果没有更多的代码或实际示例,很难知道发生了什么。

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

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