javascript - jquery mobile changePage() 无法正常工作

标签 javascript jquery-mobile cordova

我正在使用 phonegap 和 jquerymobile 创建一个网络应用程序。当我使用 changePage 转到其他页面时,它不起作用。这是我的代码

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width; user-scalable=no" />
<script type="text/javascript" charset="utf-8" src="phonegap-1.4.1.js"></script>
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<link rel="stylesheet" href="jquery.mobile-1.0.1.min.css" />
<script type="text/javascript" src="jquery.mobile-1.0.1.min.js"></script>
</head>

<script type="text/javascript">
function clickEvent()
{
    $.mobile.changePage("account_page.html", null, true, true);
}
</script>
<body>
<div style="top: 0; left: 0; position: absolute; z-index: 1;">
    <img src="images/login_screen.JPG" alt="login_screen" width="320"    onclick="clickEvent()"/>
</div>
</body>
</html>

但是当我使用

window.location.href = 'file:///android_asset/www/account_page.html';

那么它正在工作...为什么会这样?

最佳答案

$.mobile.changePage 不会将另一个 html 加载到 View 中。它扫描您提供链接的 html 中的 html,获取其上的第一个 jqm“页面”并将其添加到 dom(而不是整个 html)
如果这不是您打算做的并且想要加载将完整的 account_page.html 放入 dom 然后你将不得不使用

window.location.href or navigator.app.loadUrl

关于javascript - jquery mobile changePage() 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9361422/

相关文章:

javascript - 将数据传递给 Vue 组件?

javascript - 从 JSON 填充组合框(按字符串)

javascript - 是否可以清除 Ionic 中的 View 缓存?

javascript - 返回 JSX 的 React 类方法的流注释

javascript - JQuery mobile 中的多个可过滤选择菜单

css - 在 Jquery Mobile 中,如何在 iPad 的手机间隙应用程序中禁用放大镜?

javascript - 使用 Javascript 为 phonegap 应用程序推送通知?

node.js - 在 cordova(3.0.0) 中添加 blackberry10 平台显示 "Error: node cannot be found on the path. Aborting"

android - 当应用程序处于后台时,HTTP 请求因后台节流而停止

javascript - 如何仅对数组中的数值进行排序?