【问题标题】:mobile.changePage to nextPage?mobile.changePage 到 nextPage?
【发布时间】:2011-02-24 22:32:47
【问题描述】:

如何更改下面的代码以滑动到下一页/“to:url”而无需为每次页面更改编写脚本?

    <script type="text/javascript">
            $('div').live("swipeleft", function(){
                $.mobile.changePage("#pg02", "slide", false, true);
            });
            $('div').live("swiperight", function(){
                $.mobile.changePage("#pg01", "slide", true, true);
            }); 
    </script>

【问题讨论】:

    标签: java jquery android jquery-mobile


    【解决方案1】:

    将您的页面重命名为 pg1 pg2, ..., pg10,前面没有零

    <script type="text/javascript">
    
     window.now=1;
    
            $('div').live("swipeleft", function(){
                window.now++
                $.mobile.changePage("#pg"+window.now, "slide", false, true);
            });
            $('div').live("swiperight", function(){
                window.now--;
                $.mobile.changePage("#pg"+window.now, "slide", true, true);
            }); 
    </script>
    

    您必须添加一些ifs 来保护第一页和最后一页。 您可能还想将 now 变量放在不在 window 对象的全局范围内的其他对象中。

    【讨论】:

    • 谢谢!!我知道它必须如此简单。我正在尝试几乎相同的东西,但没有运气。效果很好!再次感谢。
    • 对不起,我说得太早了。我开始添加页面(在 3 个之后),并发现代码会导致它一次跳转两个页面 - 有什么想法吗?
    • 这是因为你必须正确绑定事件。假设您知道自己在做什么,我只是使用了您的示例。当您在 div 中滑动 div 时,此事件会触发多次。将它绑定到更独特的东西上。试试$('body').bind( 或者只是绑定到一个按钮
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多