问题
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