简体   繁体   English

jQuery移动后退按钮未显示在第一页上

[英]jquery mobile back button does not display on first page

i have an app written with: 我有一个写有的应用程序:

jquery 1.11.1 jquery mobile 1.4.5 cordova 4.3.0 jQuery 1.11.1 jQuery Mobile 1.4.5 Cordova 4.3.0

my index.html looks like 我的index.html看起来像

<div data-role="page" id="id1">

  <div data-role="header" data-add-back-btn="true" style="height: auto">
      <h1>Page 1</h1>
  </div>

  <div data-role="content">
  </div>
</div>

<div data-role="page" id="id2">

  <div data-role="header" data-add-back-btn="true" style="height: auto">
      <h1>Page 2</h1>
  </div>

  <div data-role="content">
  </div>
</div>

. . .

  <div data-role="header" data-add-back-btn="true" style="height: auto">
      <h1>Page X</h1>
  </div>

  <div data-role="content">
  </div>
</div>

i have onLoad() and onDeviceReady() 我有onLoad()和onDeviceReady()

when my app starts i get the splash screen and then 当我的应用启动时,出现启动画面,然后

<div data-role="page" id="id1">

displays. 显示器。 but it has NO back button despite data-add-back-btn="true" 但尽管有data-add-back-btn =“ true”,但它没有后退按钮

when 什么时候

<div data-role="page" id="id2">

displays it DOES have a back button. 显示它没有后退按钮。

i don't understand what's wrong. 我不明白怎么了。 am i displaying the first page before before jquery mobile is ready enough to display the back button? 我是否在jquery mobile准备好显示后退按钮之前显示第一页?

You can't have a back button on a first page. 您在首页上不能有返回按钮。

What would be the point, where would it point to? 重点是什么?

There's a workaround, create a third page, call it a dummy page. 有一种解决方法,创建第三页,将其称为虚拟页面。 Make it empty and make it first in line. 将其清空并使其排成一行。 On pagecontainercreate (or pagecreate even if you're using older page events) just programmatically change page to #id1. 在pagecontainercreate上(即使您正在使用旧的页面事件,也可以使用pagecreate)以编程方式将页面更改为#id1。 This way you won't even notice dummy page and your now second page will have a back button. 这样,您甚至都不会注意到虚拟页面,而您现在的第二个页面将有一个后退按钮。

Working example: http://jsfiddle.net/4y7mav4a/ 工作示例: http : //jsfiddle.net/4y7mav4a/

HTML HTML

    <div data-role="page" id="hidden">

    </div>

    <div data-role="page" id="id1">

      <div data-role="header"  data-add-back-btn="true" style="height: auto">
          <h1>Page 1</h1>
      </div>

      <div data-role="content">
          <a href="#id2">Go to page 2</a>
      </div>
    </div>

    <div data-role="page" id="id2">

      <div data-role="header" data-add-back-btn="true" style="height: auto">
          <h1>Page 2</h1>
      </div>

      <div data-role="content">
      </div>
    </div>

JavaScript JavaScript的

$(document).on('pagecreate', '#hidden', function(){ 
    $(":mobile-pagecontainer").pagecontainer("change", "#id1");        
});
<div data-role="page" id="id1">

  <div data-role="header" data-add-back-btn="true" style="height: auto">
      <h1>Page 1</h1>
  </div>

I had a similar problem and i solved it by adding this code 我有一个类似的问题,我通过添加此代码解决了

<a href="#page1" data-icon="arrow-l">Back</a>, 

rigth after the: 严厉之后:

<div data-role="header" data-add-back-btn="true" style="height: auto">

Like this: 像这样:

<div data-role="header" data-add-back-btn="true" style="height: auto">
      <a href="#page1" data-icon="arrow-l">Back</a>
<h1>Page 1</h1>
  </div>

With this you can have a back button wherever you want, the only problem is that you have to put a specific page, and you can erase the data-add-back-btn="true" 有了这个,您可以在任何地方有一个后退按钮,唯一的问题是您必须放置一个特定的页面,并且可以擦除data-add-back-btn =“ true”

I hope this could help you or anyone else with this need 我希望这可以帮助您或其他有此需要的人

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

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