jQuery Mobile: Prevent node being deleted on history back

落花浮王杯 提交于 2019-12-25 06:55:29

问题


I have this code

$(function() {
  $(window).on("swipeleft", jqmForward).on("swiperight", jqmBack);
});

function jqmBack(e) {
  var prevpage = $('div.ui-page-active').prevAll('div[data-role="page"]');
  if (prevpage.length > 0)
    $.mobile.changePage($(prevpage[0]), { transition: "slide", reverse: true }, true, true);
}
function jqmForward(e) {
  var nextpage = $('div.ui-page-active').nextAll('div[data-role="page"]');
  if (nextpage.length > 0)
    $.mobile.changePage($(nextpage[0]), "slide", false, true);
}

But the forward function never works because apparently jqm deletes the latest div.ui-page when you go back.

Is there a way to keep the div.ui-page to let you go forward after you accidentally swipe right (ie. go back)?

I am using jQuery Mobile 1.4.0


回答1:


The solution is to have

$(function () {
  $.mobile.page.prototype.options.domCache = true;
});

(see Caching pages in DOM). But that rises another problem.



来源:https://stackoverflow.com/questions/22001749/jquery-mobile-prevent-node-being-deleted-on-history-back

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!