简体   繁体   English

关闭弹出窗口并导航到jQuery Mobile中的另一个页面

[英]Close popup and navigate to another page in jQuery Mobile

I'm trying to close a popup / dialog when a user presses a button inside the popup, and navigate to another page (single page application, multiple "pages"). 我试图在用户按下弹出窗口中的按钮时关闭弹出窗口/对话框,并导航到另一个页面(单页面应用程序,多个“页面”)。 jQM 1.4.0 jQM 1.4.0

If I tap the YES-button inside the popup, it will navigate to #page3 wich I want but then jump back to the startpage. 如果点击弹出窗口中的“是”按钮,它将导航至所需的#page3,然后跳回到起始页。 If I comment out the .popup("close"); 如果我注释掉.popup(“ close”); it works, but I need to close the popup before I do stuff. 它可以工作,但是我需要先关闭弹出窗口,然后再进行操作。 What is wrong here? 怎么了

js JS

$("#popupyes").on("tap", function(e)
    {
        $("#popupDialog").popup("close"); // <---- doesn't work

        //call some js-function before navigate to #page3
    });

html HTML

<a href="#popupDialog" data-rel="popup" data-position-to="window" data-transition="pop" class="ui-btn ui-corner-all ui-shadow ui-btn-a">Button</a>

            <div data-role="popup" id="popupDialog" data-overlay-theme="a" data-theme="a" data-dismissible="false" style="max-width:400px;">
                <div data-role="header" data-theme="a">
                <h1>Head</h1>
                </div>
                <div data-role="main" class="ui-content">
                    <h3 class="ui-title">Text.</h3>
                <p>Text?</p>
                    <a href="#page3" class="ui-btn ui-corner-all ui-shadow ui-btn-inline ui-btn-a">No</a>
                    <a href="#" class="ui-btn ui-shadow ui-corner-all ui-btn-inline ui-btn-icon-right ui-icon-delete" data-rel="back">Abort</a>
                    <a id="popupyes" href="#page3" class="ui-btn ui-shadow ui-corner-all ui-btn-inline">Yes</a>
                </div>
            </div>  

Update I can use $("#popupDialog").hide(); 更新我可以使用$("#popupDialog").hide(); But then it's still in memory, only hidden... or wait, will it terminate by itself after a while? 但是它仍然在内存中,只有隐藏...或等待,它会在一段时间后自行终止吗?

You can simply listen to popupafterclose to call any function after popup is completely closed. 您可以简单地听popupafterclose以在完全关闭弹出窗口后调用任何函数。

$(document).on("pagecreate", function () {
    $("#popupID a").on("tap", function () {
        /* do something */
        $("#popupID").popup({
            afterclose: function () {
              /* do something */
            }
        }, "close");
    });
});

Demo 演示

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

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