简体   繁体   中英

JQuery Mobile changePage() to same page after swipe

I am trying to change the page with JQuery Mobile's function changePage() afer a swipe event. The new page which is loaded is the same as the current page, only with different parameters (in my case it's a calender with year and month as parameter).

I've broken it down to a simple example:

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>

But this only works for the first swipe. After the second swipe I get a script error:

TypeError: b.data("mobile-page") is undefined Quelldatei: http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js Zeile: 3

I've tried with different transitions but all with the same result.

Any ideas what's wrong here?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM