2011-12-22 79 views
3

我正在jquery移动项目上工作。我有两个HTML页面。从index.html我有一个swipeleft事件page.html,它工作正常。从page.html我想swiperight,所以我回到index.html但这不会工作。如何使用jquery mobile从一个html页面滑回另一个页面

如果我在单个文档内部的内部页面之间滑动,而不是在html页面之间滑动,代码工作正常。我需要使用几个HTML页面。

有没有人得到这个工作?将不胜感激的答案。

在我的index.html页面这我我刷卡代码:

<script> 
$(document).ready(function() { 

$("#main").bind('swipeleft',function(event, ui){ 
     $.mobile.changePage("page.html", "slide"); 
}) 

}) 
</script> 

这是我为我的page.html中的代码:

<script> 
$(document).ready(function() { 

$("#main").bind('swiperight',function(event, ui){ 
     $.mobile.changePage("index.html", "slide"); 
}) 

}) 
</script> 

回答

0

你不应该使用$。就绪() ,您应该使用pageInit()
此外,请确保您网页上的所有ID在所有网页中都是唯一的,而不仅仅是网页的唯一ID。

0

我在所有页面上使用下面的代码进行导航,在所有页面上滑动它的工作正常,但他们没有滑动动画。

$("#main").bind('swipeleft',function(event, ui){ 
     goPage1(); 
}) 
$("#main").bind('swiperight',function(event, ui){ 
     goPage2(); 
}) 

function goPage1(){ 
    var dirPath = dirname(location.href); 
    var fullPath = dirPath + "/page1.html"; 
    window.location=fullPath; 
} 

function goPage2(){ 
    var dirPath = dirname(location.href); 
    var fullPath = dirPath + "/page2.html"; 
    window.location=fullPath; 
} 
function dirname(path){ 
    return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, ''); 
} 
相关问题