JavaScript不适用于滑动页面

JavaScript不适用于滑动页面,javascript,jquery,cordova,jquery-mobile,Javascript,Jquery,Cordova,Jquery Mobile,我正在跟踪调查。代码示例在JSFIDLE上运行良好,但是我无法使其在我的cordova移动应用程序中运行 我已将javascript代码放在js文件夹中的home.js中 home.js: $(document).on('swipeleft', '.ui-page', function(event){ if(event.handled !== true) // This will prevent event triggering more then once {

我正在跟踪调查。代码示例在JSFIDLE上运行良好,但是我无法使其在我的cordova移动应用程序中运行

我已将javascript代码放在js文件夹中的home.js中

home.js:

$(document).on('swipeleft', '.ui-page', function(event){
    if(event.handled !== true) // This will prevent event triggering more then once
    {
        var nextpage = $.mobile.activePage.next('[data-role="page"]');
        // swipe using id of next page if exists
        if (nextpage.length > 0) {
            $.mobile.changePage(nextpage, {transition: "slide", reverse: false}, true, true);
        }
        event.handled = true;
    }
    return false;
});

$(document).on('swiperight', '.ui-page', function(event){
    if(event.handled !== true) // This will prevent event triggering more then once
    {
        var prevpage = $(this).prev('[data-role="page"]');
        if (prevpage.length > 0) {
            $.mobile.changePage(prevpage, {transition: "slide", reverse: true}, true, true);
        }
        event.handled = true;
    }
    return false;
});
home.html

<!DOCTYPE html>
<html>
<head>
    <title>Share QR</title>
    <meta name="viewport" content="width=device-width,height=device-height,minimum-scale=1,maximum-scale=1"/>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css" />
    <!--<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>-->
    <script type="text/javascript" src="js/home.js"></script>

    <script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
</head>

<body>
<div data-role="page" id="article1">
    <div data-role="header" data-theme="b" data-position="fixed" data-id="footer">
        <h1>Articles</h1>
    </div>
    <div data-role="content">
        <p>Article 1</p>
    </div>
</div>

<div data-role="page" id="article2">
    <div data-role="header" data-theme="b" data-position="fixed" data-id="footer">
        <a href="#article1" data-icon="home" data-iconpos="notext">Home</a>
        <h1>Articles</h1>
    </div>
    <div data-role="content">
        <p>Article 2</p>
    </div>
</div>

<div data-role="page" id="article3">
    <div data-role="header" data-theme="b" data-position="fixed" data-id="footer">
        <a href="#article1" data-icon="home" data-iconpos="notext">Home</a>
        <h1>Articles</h1>
    </div>
    <div data-role="content">
        <p>Article 3</p>
    </div>
</div>

</body>
</html>

共享QR
文章
第一条

文章 第二条

文章 第三条


我无法滑动以更改页面。有人能给我指出正确的方向吗?

似乎您的HTML中缺少了“ui页面”类

<div class="ui-page" data-role="page" id="article1">

您似乎缺少HTML中的“ui页面”类

<div class="ui-page" data-role="page" id="article1">


到第一个div标签还是到all 3?我想全部3个,否则这些滑动事件绑定到什么?除非这是特定于Cordova的内容,否则最好使用本机页面转换:。而不是复制针对不同情况的答案:
ui页面
在创建页面时动态添加。除非您熟悉框架,否则不要发布答案。很公平,我的错误是第一个div标记还是全部3?我想全部3个,否则这些滑动事件将绑定到什么?除非这是特定于Cordova的内容,否则最好使用本机页面转换:。而不是复制针对不同情况的答案:
ui页面
在创建页面时动态添加。除非你熟悉这个框架,否则不要发布答案。公平地说,我的错误是在jquery-mobile.js之后而不是之前加载home.js。在jquery-mobile.js之后而不是之前加载home.js。