2013-08-31 65 views
2

我正在嘗試使用JQuery Mobile的函數changePage()更改頁面刷新事件。加載的新頁面與當前頁面相同,只有不同的參數(在我的情況下,它是以年份和月份爲參數的日曆)。JQuery Mobile changePage()刷到同一頁後

我打破它歸結爲一個簡單的例子:

test.php的:

<!DOCTYPE html> 
<html> 
<head> 
<title>Test</title> 

<meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
<meta charset="utf-8"> 

<meta name="viewport" content="width=device-width, initial-scale=1"> 
<meta name="apple-mobile-web-app-capable" content="yes"> 

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" /> 
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> 
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script> 

<script type="text/javascript">  
    $(document).on("pageinit","#main",onPageInit); 

    function onPageInit(event) 
    {   
     $(document).on("swipeleft","#main",onSwipeLeft); 
     <?php 
     if ($_GET['id'] > 0) 
     { 
      ?>    
      $(document).on("swiperight","#main",onSwipeRight); 
      <?php 
     } 
     ?>   
    }    
    function onSwipeLeft(event) 
    { 
     //alert ("left"); 
     //$.mobile.changePage("test.php?id=<?php echo $_GET['id'] + 1 ?>", { transition: "slide", allowSamePageTransition: true, reloadPage: true});  
     $.mobile.changePage("test.php?id=<?php echo $_GET['id'] + 1 ?>", { transition: "none", allowSamePageTransition: true }); 
    } 
    function onSwipeRight(event) 
    { 
     //alert ("right"); 
     //$.mobile.changePage("test.php?id=<?php echo $_GET['id'] - 1 ?>", { transition: "slide", allowSamePageTransition: true, reloadPage: true}); 
     $.mobile.changePage("test.php?id=<?php echo $_GET['id'] - 1 ?>", { transition: "none", allowSamePageTransition: true });    
    }  
</script> 
</head> 

<body> 
<div data-role="page" id ="main" data-theme="a"> 
<div data-role="content" id ="content" data-theme="a">   
    <?php echo $_GET['id'] ?>  
</div> 
</div> 
</body> 
</html> 

但對於第一次刷卡這隻作品。第二刷卡後,我得到一個腳本錯誤:

類型錯誤:b.data(「移動頁」)是未定義 Quelldatei:http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js Zeile:3

我試着用不同的過渡,但所有相同的結果。

任何想法這裏有什麼不對?

回答

0

也許作品:$(document).one("pageshow","#main",onPageInit);