Jquery移动更改页面,后退按钮不起作用 [英] Jquery mobile changepage with back button not working

查看:94
本文介绍了Jquery移动更改页面,后退按钮不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的JQM主HTML文件中有4个页面。当我使用changepage切换到一个时,它第一次没问题,但我使用data-rel = back按钮返回,然后切换到上一页,但随后弹回到有后退按钮的页面。我应该不使用data-rel = back吗?如果不是有什么替代方案?

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?

使用JQM 1.3.1

Using JQM 1.3.1

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

第二页按钮

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


推荐答案

要以编程方式转到上一页,请使用以下代码。您还需要使用 stopImmediatePropagation(); 阻止jQuery Mobile跳两次,这将显示相​​同的页面。

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.

编辑:我在iPad上测试过, preventDefault()也是必需的。

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 });
});

这篇关于Jquery移动更改页面,后退按钮不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆