【问题标题】:JQuery Mobile changePage() to same page after swipe滑动后 JQuery Mobile changePage() 到同一页面
【发布时间】:2013-09-04 04:51:25
【问题描述】:

我正在尝试在滑动事件之后使用 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") 未定义 奎尔达泰:http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js 蔡勒:3

我尝试了不同的转换,但结果都一样。

有什么想法吗?

【问题讨论】:

    标签: php javascript jquery html jquery-mobile


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2012-05-22
      • 1970-01-01
      • 1970-01-01
      • 2015-05-31
      • 2011-12-10
      • 1970-01-01
      • 2015-03-04
      • 1970-01-01
      • 2013-12-06
      相关资源
      最近更新 更多