简体   繁体   English

如果jQuery Mobile弹出窗口打开,如何通过jQuery检查?

[英]How do I check via jQuery if a jQuery Mobile popup is open?

I'm able to activate the following jQuery Mobile popup: 我可以激活以下jQuery Mobile弹出窗口:

<div data-role="popup" id="waiting1" data-overlay-theme="a" data-corners="false" data-tolerance="30,15" data-dismissible="false">
     <div class="modalAlert" id="waitingContent">
      Waiting...
     </div> 
</div>

using the jQuery command: 使用jQuery命令:

$(waiting1).popup('open');

but then I want to confirm programmatically that the popup opened, and trigger an alert using an IF statement if it didn't. 但后来我想以编程方式确认弹出窗口打开,如果没有,则使用IF语句触发警报。 I tried using the CSS display attribute: 我尝试使用CSS显示属性:

if ( $(waiting1).css('display') != 'block') {
    alert(
        "Error: Waiting popup should not be visible."
    );
    return( -1 );
};

...but as a jQuery Mobile popup, apparently the attribute is always "block" whether it's visible or not. ...但作为一个jQuery Mobile弹出窗口,显然该属性始终是“阻止”,无论它是否可见。 What's the proper way to check this within the IF statement? 在IF语句中检查这个的正确方法是什么? Thanks for any help. 谢谢你的帮助。

In jQuery Mobile, a class gets applied to the popup's container when it appears. 在jQuery Mobile中,类出现时会应用于弹出窗口的容器。 ui-popup-active when it's visible, ui-popup-hidden when it's hidden. ui-popup-active当它ui-popup-hidden时, ui-popup-hidden隐藏起来。 Therefore instead of checking for 'block' or ':visible' , you could check for the that class: 因此,您可以检查该类,而不是检查'block'':visible'

if ( $(waiting1).parent().hasClass('ui-popup-hidden')) {
    alert(
        "Error: Waiting popup should not be visible."
    );
    return( -1 );
};

We can use the jQuery Mobile Popup mutex: 我们可以使用jQuery Mobile Popup互斥锁:

if ($.mobile.popup.active && $.mobile.popup.active.element[0] === $(waiting1)[0]) {
alert('popup is opened');
}

Suppose popup has the class popupLogin 假设popup有类popupLogin

if ($.mobile.activePage.find(".popupLogin").parent().hasClass("ui-popup-active")){
     alert('popup is open');
}

See this jsfiddle: http://jsfiddle.net/umerqureshi/fuy4Lz5z/ 看到这个jsfiddle: http//jsfiddle.net/umerqureshi/fuy4Lz5z/

这对我有用:

if(!$.mobile.activePage.find(popupID).is(":visible")) $(popupID).popup('close');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM