Javascript jqueryui自动打开

Javascript jqueryui自动打开,javascript,jquery,jquery-ui,Javascript,Jquery,Jquery Ui,有人能帮我把jQuery UI对话框设置为自动打开吗?谢谢我当前的代码: <script type="text/javascript"> function openDialog(url) { $("<div class='popupDialog'>Loading...</div>") .dialog({ autoOpen: true, closeOnEscape: true,

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

函数openDialog(url){
$(“正在加载…”)
.对话({
自动打开:对,
closeOnEscape:没错,
宽度:“自动”,
高度:“自动”,
莫代尔:是的,
beforeClose:function(){$(this.remove();}
}).bind('dialogclose',function(){
对话框('destroy');
}).load(url,函数(){
$(此).dialog(“选项”、“位置”、“中心”、“中心”);
$(此).dialog(“打开”);
});
}
$(窗口)。调整大小(函数(){
$(“.ui对话框内容”).dialog(“选项”、“位置”、“中心”、“中心”);
});

我想这就是你想要的:

$(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']);
    });
});
$(document).ready(函数(){//影响DOM的所有jQuery代码都应该在DOM处于readyState之后运行。
“使用严格”;//ECMAScript 5,耶!
var url='www.somsite.com';
函数openDialog(url){
//添加了返回语句以返回对话框
//使用“content”作为“选择器”将创建一个未附加到DOM的新div元素。
返回$('Loading…')。对话框({
“自动打开”:正确,
“closeOnEscape”:没错,
“宽度”:“自动”,
“高度”:“自动”,
“模态”:正确,
“beforeClose”:函数(){
$(this.remove();
}
}).bind('dialogclose',函数(){
$(this.dialog('destroy');
}).load(url、函数(){
$(此).dialog('option','position',['center','center']);
$(this.dialog('open');
});
}
$('body').append(openDialog(url));//将创建的DOM元素追加到DOM
$(窗口)。调整大小(函数(){
$('.ui对话框内容')。对话框('option','position',['center','center']);
});
});

您当前的代码中有什么不起作用?我猜你的对话没有打开,但可能是其他原因。检查浏览器控制台中的代码是否有任何错误。