我有一个 JQuery 移动应用程序。在应用程序的第一页上,我正在尝试在加载时设置一些字段值(如果之前已设置)。为了做到这一点,我目前有以下内容:
索引.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<link rel="stylesheet" href="/resources/css/themes/mobile/core.css" />
<link rel="stylesheet" href="/resources/css/themes/mobile/app.css" />
<script type="text/javascript" src="/resources/scripts/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="/resources/scripts/app.ui-1.0.js"></script>
<script type="text/javascript" src="/resources/scripts/jquery.mobile-1.3.0.min.js"></script>
</head>
<body>
<div id="loginPage" data-role="page">
<div data-role="header" data-position="fixed"><h1>AppName</h1></div>
<div data-role="content">
<label for="usernameTextBox">Username</label>
<input id="usernameTextBox" type="text" autocomplete="false" /><br />
<label for="passwordTextBox">Password</label>
<input id="passwordTextBox" type="password" /><br />
<div class="ui-grid-a"><div class="ui-block-a">
<a href="#" id="loginButton" data-role="button" class="dd-btn-a" onclick="return loginButton_Click();">Login</a></div>
</div>
</div>
</div>
</body>
</html>
app.ui.js
$("#loginPage").on("pagecreate", function () {
alert("here 1");
$.mobile.hidePageLoadingMsg();
});
$("#loginPage").on("pageshow", function () {
alert("here 2");
$.mobile.hidePageLoadingMsg();
var us = false;
var ps = false;
var u = window.localStorage.getItem("username");
if ((u != null) && (u != undefined) && (u.length > 0)) {
if (u != "undefined") {
$("#usernameTextBox").val(u);
us = true;
}
}
alert(u);
var p = window.localStorage.getItem("password");
if ((p != null) && (p != undefined) && (p.length > 0)) {
if (p != "undefined") {
$("#passwordTextBox").val(p);
ps = true;
}
}
if ((us == true) && (ps == true)) {
loginButton_Click();
}
});
奇怪的是,我的“警报”框都没有被触发。此外,我在控制台窗口中看不到任何错误。我究竟做错了什么?