【发布时间】:2013-11-26 08:45:19
【问题描述】:
我的问题是 Jquery mobile 的 changePage(),首先让我说我知道还有很多其他关于这个问题的帖子,但我已经尝试了所有解决方案,但没有任何运气,所以这就是我现在要求帮助。
我已经构建了一个 Phonegap 项目,其中每个屏幕都是一个 .html 文件。我得到了加载整个应用程序所需的所有脚本的 index.html。然后我的 index.html 使用 $.mobile.changePage() 加载一个新页面。但是当这种情况发生时,下一页确实有任何脚本或 css 附加到它上面,为什么?
这如果我的 index.html
<!--index page used to find out if the user should see the login or welcome page-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery Mobile Web App</title>
<link href="jquery-mobile/jquery.mobile.theme-1.3.2.min.css" rel="stylesheet" type="text/css"/>
<link href="jquery-mobile/jquery.mobile.structure-1.3.2.min.css" rel="stylesheet" type="text/css"/>
<link href="jquery-mobile/jquery.mobile-1.3.2.min.css" rel="stylesheet" type="text/css"/>
<link href="jquery-mobile/jqm-icon-pack-2.0-original.css" rel="stylesheet" type="text/css"/>
<link href="jquery-mobile/jqm-icon-pack-fa.css" rel="stylesheet" type="text/css"/>
<script src="jquery-mobile/jquery-1.10.2.min.js" type="text/javascript"></script>
<!--Used to make sure theres as little delay on old devises as possible-->
<script src="buttonTapDelayJS.js" type="text/javascript"></script>
<script src="jquery-mobile/jquery.mobile-1.3.2.min.js" type="text/javascript"></script>
<script src="loginJS.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script src="menuJS.js" type="text/javascript"></script>
<script src="generalFunctionsJS.js" type="text/javascript"></script>
<script src="javaIndex.js" type="text/javascript"></script>
<script src="myJavaScript.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script src="menuJS.js" type="text/javascript"></script>
<script src="generalFunctionsJS.js" type="text/javascript"></script>
<!--Loads the css for the menu-->
<link href="menuStyle.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
var checkUser="admin";
function onDeviceReady() {
/*if the stored username is = the correctusername, it loads the welcome page if not it loads the login*/
if(window.localStorage.getItem("user") === checkUser){
$.mobile.changePage("welcome.html",{transition:"slide"});
//window.open("welcome.html", "_self");
} else {
//window.open("login.html", "_self");
$.mobile.changePage("login.html",{transition:"slide"});
}
}
</script>
</head>
<body onload="onDeviceReady()">
</body>
</html>
这是我的登录页面
<!--Login page-->
<!DOCTYPE html>
<html>
<body onload="loadLogin();">
<!--Creates all content you see on the screen-->
<div data-role="page" id="login">
<div data-role="content">
<ul data-role="listview">
<div align="center" data-role="content">
<img src="icon.png" alt="">
</div>
<div data-role="content">
<label for="textinput">Indtast brugernavn</label>
<input type="text" name="textinput" id="textinput" value=""/>
</div>
<div data-role="content">
<label for="passwordinput">Indtast adgangskode</label>
<input type="password" name="passwordinput" id="passwordinput" value="" />
</span> </div>
<div data-role="content">
<div><a href="#" data-role="button" onClick="saveLogin();myFunction();">Login</a></div>
</div>
<div data-role="content">
<div><a href="#" id="infoButton" data-role="button" data-icon="info" data-theme="b" onClick="infoPopup();"></a></div>
</div>
</ul>
</div>
</div>
</body>
</html>
如开头所述,我的问题是我的登录页面上的所有函数都不能举例说明我的 infoButton 运行 onClick="infoPopup(); 并且此函数会弹出 navigator.notification .alert("Message", null, "Info", "OK"); 但是当我按下它时它确实没有显示任何内容。
我是在加载我的脚本错误还是出了什么问题,非常感谢任何帮助?
编辑 1: 如果我将所有 index.html 复制到所有其他页面,会发生什么。我的 index.html 链接到我的 login.html 正确。在登录页面上我的 onClick="infoPopup(); dosent 工作,但我的 onClick="saveLogin();myFunction();" 有点工作。我的登录信息确实被保存但在我的 saveLogin(); 我有一个导航器.notification.alert(); 但警报并没有弹出。我知道我的所有功能都有效,因为当我使用 window.open(); 而不是 changePage 时它们都有效。我改变的原因是因为 window.open (); 我无法获得 jquery 页面转换有什么想法吗?
编辑 2: 真的不知道我做了什么,但现在可以工作了:) 感谢您的回复。 即使我已经厌倦了这对我有用的是将所有 javascripts 和 css 移动到 index.html。
【问题讨论】:
-
在页面div
data-role=page内添加其他页面的js代码。 -
我厌倦了链接 loginJS 包含登录功能,作为但是没有发送工作如果我将所有 index.html 复制到所有其他页面,会发生这种情况。我的 index.html 链接到我的 login.html 正确。在登录页面上我的 onClick="infoPopup(); dosent 工作,但我的 onClick="saveLogin();myFunction();" 有点工作。我的登录信息确实被保存但在我的 saveLogin(); 我有一个导航器.notification.alert(); 但警报并没有弹出。我知道我的所有功能都有效,因为当我使用 window.open(); 而不是 changePage 时它们都有效。我改变的原因是因为 window.open (); 我无法获得 jquery 页面转换有什么想法吗?
标签: javascript jquery-mobile mobile cordova