简体   繁体   English

jQuery Mobile changepage更改页面比返回上一页

[英]JQuery Mobile changepage changes the page than go back to the previous page

I´m trying to use $.mobile.changePage inside a popup anchor to change to another page but when I click the anchor inside the popup the page changes and then back to the previous page again. 我正在尝试使用弹出锚中的$ .mobile.changePage更改为另一个页面,但是当我单击弹出窗口中的锚时,页面将更改,然后再次返回到上一页。

I tried this solution: changePage "jumps" back to old page using this: $(document).bind("mobileinit", function(){ $.mobile.pushStateEnabled = false; }); 我尝试了以下解决方案: changePage使用此命令“跳转”回旧页面 :$(document).bind(“ mobileinit”,function(){$ .mobile.pushStateEnabled = false;});

but it didn't work either. 但它也不起作用。

This is how I built my page: 这是我建立网页的方式:

<div id="pgTest" data-role="page" data-theme="a">
    @Html.Partial("_Header", new WebApp.Models.HeaderModel() { Header = "Title" })
    <div data-role="ui-content">
        <div style="width:90%; margin:0 auto;">
            @Html.Partial("_ListViewWithFilter", Model)

            <!--Pop Up-->
            <div data-role="popup" id="popupConfirmacao" data-dismissible="false" data-overlay-theme="a" class="ui-corner-all">
                <div role="main" class="ui-content">
                    <h3 class="ui-title" id="dialogTitle"></h3>
                    <a id="linkConfirmacaoDialog" href="#" class="ui-btn ui-corner-all ui-shadow ui-btn-inline ui-btn-b" data-rel="back">Sim</a>
                    <a href="#" class="ui-btn ui-corner-all ui-shadow ui-btn-inline ui-btn-b" data-rel="back">Não</a>
                </div>
            </div>
            <!--Pop Up ends-->
        </div>
    </div>
    @Html.Partial("_Footer")
</div>

and this is my JS: 这是我的JS:

<script type="text/javascript">
        $(function () {
            var itens = $('#ulMusicas>li');
            itens.click(function () {
                var nomeMusica = $(this).find('a').text();
                $('#dialogTitle').text('Add "' + nomeMusica + '"?');
                $('#linkConfirmacaoDialog').click(function () {                    
                    $.mobile.changePage('/Controller2');
                });
                $('#popupConfirmacao').popup('open', { positionTo: 'window', transition: 'pop' });
            });
        });
</script>

It basically creates a listview and when you click any item it will open a popup. 它基本上会创建一个列表视图,当您单击任何项​​目时,它将打开一个弹出窗口。 If you click the button on popup it should redirect you to the other page. 如果单击弹出窗口上的按钮,则应将您重定向到另一页。 At this moment jquery mobile redirects me to the other page and then backs to the previous page. 此时,jquery mobile将我重定向到另一页面,然后返回到上一页。

Anyone have any ideia what may be happening? 任何人都有任何想法可能会发生什么?

The issue is caused by data-rel="back" in #linkConfirmacaoDialog confirmation button. 该问题是由#linkConfirmacaoDialog确认按钮中的data-rel="back"引起的。 When you hit that button, you give two different navigation orders. 当您按下该按钮时,您将给出两个不同的导航顺序。 What happens is that you navigate to target page and then back in history. 发生的情况是,您导航到目标页面,然后返回历史记录。 Use data-rel="back" only when you want to close popup and remain in same page. 仅当您要关闭弹出窗口并保留在同一页面中时,才使用data-rel="back"

Another issue, popup div shouldn't be wrapped in div other than page div . 另一个问题是, 弹出 div除页面div之外不应包装在div中 Moreover, you are adding multiple click listeners to #linkConfirmacaoDialog whenever a list item is clicked. 此外,每当单击列表项时,您都将向#linkConfirmacaoDialog添加多个click侦听器。 Place click binding outside other click binding. click绑定置于其他click绑定之外。

$(function () {
    var itens = $('#ulMusicas>li');
    /* list item click listener */
    itens.click(function () {
        var nomeMusica = $(this).find('a').text();
        $('#dialogTitle').text('Add "' + nomeMusica + '"?');
        $('#popupConfirmacao').popup('open', {
            positionTo: 'window',
            transition: 'pop'
        });
    });
    /* confirmation button - popup */
    $('#linkConfirmacaoDialog').click(function () {
        $.mobile.changePage('/Controller2');
    });
});

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

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