2

我使用我的代码如下。如果对话框已经打开,则函数 get_devcies_full 将被调用 5 次不要再次打开它,只需更新内容然后我将编码 Bellow 我在 javascript 中遇到错误

无法在初始化之前调用对话框上的方法;试图调用方法isOpen

function get_devcies_full(id,slno)
{
    $.post("user/get_full_device/" +id + "/" +slno,
        function(data) {
            var NewDialog = $('<div id="MenuDialog"></div>');
            if (NewDialog.dialog( "isOpen" )!==true){
                NewDialog.dialog({
                    modal: true,
                    title: "Title",
                    width :940,
                    height:600,
                }); 
            }
            NewDialog.html(data);
            var t = setTimeout(function () {get_devcies_full(id,slno);},5000);
        }
    );
}

请给出我遇到问题的解决方案?

4

1 回答 1

1

尝试这个:

function get_devcies_full(id,slno)
{
    $.post("user/get_full_device/" +id + "/" +slno,
        function(data) {
            if(!($("#MenuDialog").length))//if this div created for first time
            {
                $(body).append('<div id="MenuDialog"></div>');//First time you have to append this in body  
            }
            if (!$('#MenuDialog').dialog('isOpen'))
            //Try if not works => if(!($("#MenuDialog").parents(".ui-dialog").is(":visible")))
            {
                $("#MenuDialog").dialog({
                    modal: true,
                    title: "Title",
                    width :940,
                    height:600    
                });
            }
            $("#MenuDialog").html(data);
            var t = setTimeout(function () {get_devcies_full(id,slno);},5000);
        }
    );
}
于 2013-03-06T10:00:35.357 回答