滑动后JQuery Mobile changePage()到同一页面

时间:2013-08-31 16:18:05

标签: php javascript jquery html jquery-mobile

我试图在刷卡事件之后使用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>

但这仅适用于第一次滑动。第二次滑动后,我收到一个脚本错误:

TypeError:b.data(“mobile-page”)未定义 Quelldatei:http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js Zeile:3

我尝试过不同的过渡,但都有相同的结果。

这里有什么想法吗?

1 个答案:

答案 0 :(得分:0)

也许有效:$(document).one("pageshow","#main",onPageInit);

相关问题