我使用我的代码如下所示。如果对话框已经打开,函数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);
}
);
}
请问我解决问题的方法吗?
答案 0 :(得分: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);
}
);
}