javascript - 页面容器#change-JqueryMobile-Phonegap

标签 javascript cordova jquery-mobile

我有一个phonegap/jquerymobile 应用程序,我似乎无法使用pagecontainer #change 来工作。我已经尝试了我能找到的最新语法,但似乎遗漏了一些东西。

function goToCards() {
    console.log('got to goToCards');
    $(':mobile-pagecontainer').pagecontainer('change', '#cardsPage');
}
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="msapplication-tap-highlight" content="no" />
    <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
    <link rel="stylesheet" type="text/css" href="css/index.css" />
    <title>BibHub Mobile</title>
  </head>
  <body>
    <div class="app" data-role="page" id="loginPage">
      <div data-role="header">
        <h1>Biphub</h1>
      </div>
      <div data-role="content">
        <a href="#" data-role="button" onclick="goToCards()"> go to cards</a>
      </div>
    </div>
    <div class="app" data-role="page" id="cardsPage">
      <div data-role="header">
        <h1>Biphub</h1>
        <h2>Your UID is <span id="uidSpan"></span></h2>
      </div>
      <div data-role="content">
        <p>Your card stack is currently empty. Way to go!</p>
      </div>
    </div>

    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript">
      app.initialize();
    </script>
  </body>
</html>

当我在 xcode 中运行该应用程序时,我成功记录了“got to goToCards”。但是,没有页面更改或任何错误。普通的非 js 函数链接可用于转换页面。有什么想法吗?

最佳答案

pagecontainer 小部件及其方法是在 jQuery Mobile 1.4 版中引入的。您似乎使用的是非常旧的版本(1.0)。可以同时升级 jQuery 和 jQuery Mobile 版本吗?

如果没有,您需要使用 $.mobile.changePage : API DOC

关于javascript - 页面容器#change-JqueryMobile-Phonegap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33858714/

相关文章:

javascript - jQuery 快速过滤问题与搜索范围标题属性

javascript - 背景图像属性中的 GIF 图片需要停止动画

cordova - 向 Ionic 2 添加 cordova 插件

cordova - Phonegap 条码扫描器更快

javascript - Jquery Mobile 中 .mobile.loadPage 和外部页面的问题

javascript - 如何从时间戳生成哈希?

javascript - 我应该如何等待文档加载?

android - Crosswalk 的 Ionic Framework 不工作 - 不幸的是应用程序已停止

javascript - 防止用户在 jQuery Mobile 中使用 ajax 加载页面时单击其他位置

jQuery Mobile 可折叠集,如何检查 div 元素是否展开?