【问题标题】:Timed delayed auto page redirect JQuery Mobile定时延迟自动页面重定向 JQuery Mobile
【发布时间】:2016-04-26 16:29:12
【问题描述】:

您好,我正在尝试在 JQM 多页索引中使页面自动重定向到另一个页面。我还希望重定向延迟大约 3 秒。所以基本上我想要#behavior-summary(显示3秒)并自动返回#order-summary而不点击。我知道这可能有一个简单的解决方案。我在这里尝试了很多答案,但似乎不起作用。我在用 JQ 2.1.4 和 JQM 1.4.5。

另一方面,这不是启动屏幕,它将是一个 .gif,在用户输入项目后显示动画确认。现在我只使用一个按钮,正如您在#behavior-summary 上看到的那样。目标是能够在指定的时间段后删除 , no 按钮直接重定向。

以下是我尝试过的一些解决方案,但由于某种原因不起作用:

Example 1

Example 2

如果有人能提供帮助,我将不胜感激

<div data-role="page" id="order-summary">
   <div data-role="header">
        <h1>Record Drink</h1>
        <a href="#nav-panel" data-icon="bars" data-iconpos="notext">Menu</a>
   </div>
   <div data-role="content" id="summary-img">
        <img src="img/behavior_4.png"/>
        <a href="#behavior-summary" class="ui-btn ui-corner-all ui-btn-a" >Save</a>
   </div>
</div>    


<div data-role="page" id="behavior-summary">
    <div data-role="header" id="record-header">
        <h1>Record Drink</h1>
        <a href="#nav-panel" data-icon="bars" data-iconpos="notext">Menu</a>
    </div><!-- /header -->
    <div data-role="content" id="summary-img">
        <img src="img/drink_1.gif"/>
        <a href="#order-summary" class="ui-btn ui-corner-all ui-btn-a" >Save</a>
    </div>
</div>

提前谢谢你!

【问题讨论】:

    标签: javascript jquery jquery-mobile multipage timed-events


    【解决方案1】:

    您可以使用行为摘要的 pageshow 事件,然后使用延迟 3 秒的 setTimeout 和 pagecontainer 更改方法返回第一页:

    $(document).on("pageshow","#behavior-summary", function(){ 
      setTimeout(function(){
        $(":mobile-pagecontainer").pagecontainer( "change", "#order-summary", {} );
      }, 3000);
    }); 
    

    DEMO

    如果您更喜欢页面容器事件:

    $(document).on( "pagecontainershow", function( event, ui ) {
      if (ui.toPage.prop("id") == "behavior-summary" ){
        setTimeout(function(){
          $(":mobile-pagecontainer").pagecontainer( "change", "#order-summary", {  } );
        }, 3000);  
      }
    });
    

    【讨论】:

    • 谢谢我要试试这个
    【解决方案2】:
    actual have not understand your whole Q, but if you are looking for a redirect then you can use a window.location.href = '#pagname or string'; or if you want to stop the setInterval then you can use clearInterval function
    
    Please let me know if i can help you or i help understand the your pro
    

    【讨论】:

    • 我只希望页面#behavior-summary 显示5 秒,然后自动返回页面#order-summary,无需任何点击
    猜你喜欢
    • 2011-04-10
    • 1970-01-01
    • 2016-04-06
    • 2021-09-29
    • 1970-01-01
    • 2013-08-04
    • 1970-01-01
    • 2012-10-29
    • 1970-01-01
    相关资源
    最近更新 更多