简体   繁体   English

jQuery Mobile Panel不能在单击时关闭

[英]jQuery Mobile Panel does not close on click

I have a PhoneGap application wich uses a jQuery Mobile multipage layout. 我有一个使用jQuery Mobile多页布局的PhoneGap应用程序。 On every page (page A and page B) I have a navbar for switching between pages. 在每个页面上(页面A和页面B),我都有一个导航栏,用于在页面之间进行切换。 No custom code involved. 不涉及自定义代码。 I also have a panel on every page which opens by clicking the 'new' button in the header. 我在每个页面上都有一个面板,可通过单击标题中的“新建”按钮来打开该面板。

Sometimes it happens that I hit the button (maybe to soft? or to fast?) to open to panel but the buttons just changes it state to "active" and the panel does not open. 有时碰巧我按下按钮(可能是软按钮还是快速按钮)以打开面板,但是按钮只是将其状态更改为“活动”而面板没有打开。 I cannot click the button anymore. 我无法再单击该按钮。 When I change the page and go back (all by using the navbar) page A appears again and now the panel is opened. 当我更改页面并返回(全部通过使用导航栏)时,页面A再次出现,现在面板已打开。 This is a strange behaviour but could be plausible. 这是一种奇怪的行为,但可能是合理的。 But trying to close it now is just impossible. 但是现在尝试关闭它是不可能的。 Clicking one of the buttons in the panel is as inactive as clicking on the page itself. 单击面板中的按钮之一与单击页面本身一样无效。 The whole thing seems to be froozen. 整个事情似乎一团糟。

    <div data-role="page" id="one">
        <div data-role="header" data-transition="fixed">
            <a href="#panel_one" data-role="button" data-icon="grid">New</a>
            <h1 class="header">myApp</h1>
            <a href="#popup_one" data-role="button" data-rel="popup" data-icon="gear" data-iconpos="notext" data-corners="false" class="ui-btn-right" data-transition="slidedown" onclick="menu();">Options</a>
        </div>
        <!-- Header -->

        <div data-role="panel" id="panel_one">
            <div data-role="collapsible-set" class="menu"></div>
        </div>
        <!-- Panel -->

        <div data-role="content">
            <div data-role="navbar">
                <ul>
                    <li><a href="#one" data-transition="none" class="ui-btn-active" >A</a></li>
                    <li><a href="#two" data-transition="none" >B</a></li>
                </ul>
            </div>

        </div>
        <!-- Content -->
    </div>
    <!-- Page One-->

    <div data-role="page" id="two">
        <div data-role="header" data-transition="fixed">
            <a href="#panel_two" data-role="button" data-icon="grid">New</a>
            <h1 class="header">myApp</h1>
            <a href="#popup_two" data-role="button" data-rel="popup" data-icon="gear" data-iconpos="notext" data-corners="false" data-transition="slidedown" class="ui-btn-right"  onclick="menu();">Options</a>
        </div>
        <!-- Header -->

        <div data-role="panel" id="panel_two">
            <div data-role="collapsible-set" class="menu"></div>
        </div>
        <!-- Panel -->

        <div data-role="content">
            <div data-role="navbar">
                <ul>
                    <li><a href="#one" data-transition="none">A</a></li>
                    <li><a href="#two" data-transition="none" class="ui-btn-active" >B</a></li>
                </ul>
            </div>
        </div>
        <!-- Content -->
    </div>
    <!-- Page Two-->

menu() creates the content of the Menu which is not shown in the example. menu()创建菜单中未显示的内容。 Another method ( loadPanel() ) is boud to the pageshow-event and will populate the sidebar with the buttons. 另一个方法( loadPanel() )绑定到pageshow-event,并将用按钮填充侧栏。 every button will execute 每个按钮都会执行

var pageId = $.mobile.activePage.attr("id");
$("#panel_" + pageId).panel('close');

before anything else is executed. 在执行其他任何操作之前。 However, all of this works most of the time and I would just like to know if some observed a similar behaviour. 但是,所有这些操作大部分时间都是有效的,我只想知道是否有人观察到了类似的行为。

As per jQuery mobile documentation 根据jQuery mobile文档

A panel must be a sibling to the header, content and footer elements inside a jQuery Mobile page. 面板必须是jQuery Mobile页面内的header,content和footer元素的同级对象。 You can add the panel markup either before or after these elements, but not in between. 您可以在这些元素之前或之后添加面板标记,但不能在两者之间添加。

Maybe you should move up your panel because it may be the cause of the strange behaviour 也许您应该将面板向上移动,因为这可能是造成异常行为的原因

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

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