简体   繁体   中英

Jquery mobile changepage with back button not working

I have 4 pages within my JQM main HTML file. When I switch to one using changepage it's fine the first time, but I use a data-rel=back button to go back and this switches to the previous page but then bounces back to the page that has the back button. Should I just not use data-rel=back? If not what alternative is there?

Using JQM 1.3.1

$("#listView").on("vclick","li", function(e) {  
  //ajax call to get results for second page
  $.mobile.changePage('#second');
}

Button on second page

<a href="#" data-rel="back">Back</a>

To go to previous page programmatically, use the below code. You need also to use stopImmediatePropagation(); to stop jQuery Mobile from jumping twice, which will result showing the same page.

Edit: I tested it on iPad, preventDefault() is required too.

Demo

$(document).on('vclick', '[data-rel=back]', function (e) {
 e.stopImmediatePropagation();
 e.preventDefault();
 var back = $.mobile.activePage.prev('[data-role=page]');
  $.mobile.changePage(back, { 
    transition: 'slide',
    reverse: true });
});

Use this one. You can redirect between pages using location.hash=" " with page id in it.

DEMO http://jsfiddle.net/yeyene/uJz3E/7/

$("#listView").on("vclick","li", function(e) {  
  // second is the page you want to redirect on click.
  location.hash = "second";
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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