如何覆盖jquery mobile中链接对话框中关闭按钮的功能?

时间:2022-04-10 19:40:32

In jQuery Mobile I have several chained dialog boxes sliding in/out one after another when inputs were made and 'next'-buttons were clicked. But any time the close-button inside the header of the dialog box is clicked I want to get back to the initial page where the first dialog box was triggered. Normally the close button in each dialog box leads back to the page/box it was triggered from. But in my app I need to override them all to get back to the first page!

在jQuery Mobile中,我有几个链接的对话框,当输入和点击“下一个”按钮时,一个接一个地滑入/滑出。但是,只要单击对话框标题内的关闭按钮,我就会返回到触发第一个对话框的初始页面。通常,每个对话框中的关闭按钮会返回到它触发的页面/框。但在我的应用程序中,我需要覆盖它们以回到第一页!

My code:

我的代码:

<div class="ui-block-b">
    <a data-role="button" data-theme="b" data-icon="arrow-r" data-iconpos="right" 
        data-transition="slide" href="nextpage.html" data-rel="dialog">
        next
    </a>
</div>

thnx!

日Thnx!

edit: The docs say

编辑:文档说

CHAINING DIALOGS: "Please note: If a dialog opens another dialog (chaining), closing the last one with a link of type data-rel="back" will always navigate to the previous dialog until the root-page of type data-role="page" is reached. This guarantees a consistent navigation between dialogs." [http://jquerymobile.com/demos/1.2.0-beta.1/docs/pages/page-dialogs.html]

链接对话框:“请注意:如果对话框打开另一个对话框(链接),使用data-rel =”back“类型的链接关闭最后一个对话框将始终导航到上一个对话框,直到data-role类型的根页面=“页面”到达。这保证了对话框之间的一致导航。“ [http://jquerymobile.com/demos/1.2.0-beta.1/docs/pages/page-dialogs.html]

1 个解决方案

#1


1  

You can override the close method defined for the dialogs $.mobile.dialog.prototype.close:

您可以覆盖为$ .mobile.dialog.prototype.close对话框定义的close方法:

<script>

    $.mobile.dialog.prototype.close = function(){

        console.log("close");

        // DO SOMETHING HERE - EX: REDIRECTING TO MAIN PAGE
        $.mobile.changePage("index.html");
    };

    $(function() {
        console.log("document loaded");         
    });

</script>

#1


1  

You can override the close method defined for the dialogs $.mobile.dialog.prototype.close:

您可以覆盖为$ .mobile.dialog.prototype.close对话框定义的close方法:

<script>

    $.mobile.dialog.prototype.close = function(){

        console.log("close");

        // DO SOMETHING HERE - EX: REDIRECTING TO MAIN PAGE
        $.mobile.changePage("index.html");
    };

    $(function() {
        console.log("document loaded");         
    });

</script>