How to tell if any jquery dialog happens to be ope

2019-03-17 22:21发布

This question already has an answer here:

Looking for a general case solution to determine if any jquery dialog (there are multiple) is currently open. Have tried:

$(".ui-dialog-content").dialog("isOpen") === true
$(".ui-dialog").dialog("isOpen") == true
$(document).dialog("isOpen") == true
$("*").dialog('isOpen') == true

without any success. I expected ".ui-dialog-content" to work, since I can apparently close any open dialog with that selector, but it does not.

5条回答
Ridiculous、
2楼-- · 2019-03-17 23:10

Check if it's being displayed or not via CSS? Not sure if it's the right approach, but I suspect it'll work.

$(".ui-dialog").css('display') != "none"
查看更多
The star\"
3楼-- · 2019-03-17 23:15

jQuery UI dailog has a method isOpen which returns true if the dailog is open. Call it on the element which has opened the dialog box.

$('.ui-dialog-content').dialog("isOpen");

Refrence: http://jqueryui.com/demos/dialog/#method-isOpen

查看更多
相关推荐>>
4楼-- · 2019-03-17 23:22

According to the API documentation, you should use

$( ".selector" ).dialog( "isOpen" )

to determine whether the dialog is open or not. The function returns a boolean. For example,

if( $("selector").dialog("isOpen")===true ){
     /*do stuff when dialog is open*/
} else {
     /*do stuff when dialog is closed*/
};
查看更多
放荡不羁爱自由
5楼-- · 2019-03-17 23:26

you can try

if($(".ui-dialog").is(":visible")){
//dialog is open
}
查看更多
兄弟一词,经得起流年.
6楼-- · 2019-03-17 23:27
$('html').click(function() {
    x++;
    if(x==2){
    $(".ui-dialog-titlebar-close").trigger("click");
    x=0;
    }
    });

This one will work in all cases, where you call Dialog from DOM.

查看更多
登录 后发表回答