jQuery UI自动打开

jQuery UI Auto Open

本文关键字:UI jQuery      更新时间:2023-09-26

有人能帮我设置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>

我想这就是您想要的:

$(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']);
    });
});