【问题标题】:jQuery UI Auto Open [closed]jQuery UI 自动打开 [关闭]
【发布时间】:2012-02-06 20:40:23
【问题描述】:

有人可以帮我设置 jQuery UI 对话框自动打开吗?谢谢。我当前的代码:

<script type="text/javascript">
function openDialog(url) {
    $("<div class='popupDialog'>Loading...</div>")
        .dialog({
            autoOpen: true,
            closeOnEscape: true,
            width: 'auto',
            height: 'auto',
            modal: true,
            beforeClose: function(){   $(this).remove();   }
        }).bind('dialogclose', function() {
            jdialog.dialog('destroy');
        }).load(url, function() {
            $(this).dialog("option", "position", ['center', 'center'] );
                $(this).dialog("open");
        });
}

$(window).resize(function() {
    $(".ui-dialog-content").dialog("option", "position", ['center', 'center']);
});
</script>

【问题讨论】:

  • 您当前的代码有什么问题?我可以猜到你的对话框没有打开,但它可能是别的东西。检查您的浏览器控制台是否有任何代码错误。

标签: javascript jquery jquery-ui


【解决方案1】:

我想这就是你要找的:

$(document).ready(function () { //All jQuery code that affects the DOM should run after the DOM is in a readyState.
    'use strict'; //ECMAScript 5, yay!
    var url = 'www.somsite.com';
    function openDialog(url) {
        //added return statement to return the dialog
        //Using "<div>content</div>" as the "selector" creates a new div element that is not attached to the DOM.
        return $('<div class="popupDialog">Loading...</div>').dialog({
            'autoOpen': true,
            'closeOnEscape': true,
            'width': 'auto',
            'height': 'auto',
            'modal': true,
            'beforeClose': function () {
                $(this).remove();
            }
        }).bind('dialogclose', function () {
            $(this).dialog('destroy');
        }).load(url, function () {
            $(this).dialog('option', 'position', ['center', 'center']);
            $(this).dialog('open');
        });
    }
    $('body').append(openDialog(url)); //Append created DOM element to the DOM
    $(window).resize(function () {
        $('.ui-dialog-content').dialog('option', 'position', ['center', 'center']);
    });
});

【讨论】:

    猜你喜欢
    • 2012-10-14
    • 2019-09-08
    • 2012-06-17
    • 2010-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-27
    • 1970-01-01
    相关资源
    最近更新 更多