How can I tell if a jquery ui dialog query has been initialized?

我是研究僧i 提交于 2019-12-05 06:40:48

Test whether the element has the ui-dialog-content class:

if ($("#dialog-myDialog").hasClass("ui-dialog-content") &&
    $("#dialog-myDialog").dialog("isOpen")) {
    return;
}

If you use a solution which relies on the presence of a css class added by a component that is out of your control, then you run the risk of this not working if a new version of the component changes the way it manages classes.

A more reliable solution would be to add your own existence indicator at dialog initialization:

$("#popup").attr("_dialogInitialized", "yes").dialog( { ... } )

Then check for your indicator when you need to:

if ($("#popup[_dialogInitialized]").length == 1) {
    // dialog has been previously initialized
} else {
    // dialog has been not yet been initialized
}

Add a class when initilizing:

$("selector").addClass("initialized").dialog( { ... } );

Then check for the class when needed:

if ($("selector").hasClass("initialized")) { ... }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!