如果 jQuery Mobile 弹出窗口打开,我如何通过 jQuery 检查? [英] How do I check via jQuery if a jQuery Mobile popup is open?

查看:21
本文介绍了如果 jQuery Mobile 弹出窗口打开,我如何通过 jQuery 检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够激活以下 jQuery Mobile 弹出窗口:

<div class="modalAlert" id="waitingContent">等待...</div></div>

使用 jQuery 命令:

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

但是我想以编程方式确认弹出窗口已打开,如果未打开,则使用 IF 语句触发警报.我尝试使用 CSS 显示属性:

if ( $(waiting1).css('display') != 'block') {警报(错误:等待弹出窗口不应该是可见的.");返回(-1);};

...但作为一个 jQuery Mobile 弹出窗口,显然该属性始终是块",无论它是否可见.在 IF 语句中检查这个的正确方法是什么?感谢您的帮助.

解决方案

在 jQuery Mobile 中,一个类在弹出窗口的容器出现时被应用.ui-popup-active 可见,ui-popup-hidden 隐藏.因此,您可以检查该类,而不是检查 'block'':visible':

if ($(waiting1).parent().hasClass('ui-popup-hidden')) {警报(错误:等待弹出窗口不应该是可见的.");返回(-1);};

I'm able to activate the following jQuery Mobile popup:

<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:

$(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. I tried using the CSS display attribute:

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. What's the proper way to check this within the IF statement? Thanks for any help.

解决方案

In jQuery Mobile, a class gets applied to the popup's container when it appears. ui-popup-active when it's visible, ui-popup-hidden when it's hidden. Therefore instead of checking for 'block' or ':visible', you could check for the that class:

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

这篇关于如果 jQuery Mobile 弹出窗口打开,我如何通过 jQuery 检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆