我正在使用PhoneGap上的本地存储,尝试创建JavaScript登录。我目前的问题是当我运行应用程序时,如果用户名和密码正确,它将不会进入主菜单。
我认为问题出在window.location.href
方法上。我想导航到本地页面,而不是在线页面。
$(document).ready(function() {
if (typeof(localStorage) === 'undefined' ) {
alert('Your browser does not support HTML5 localStorage. Try upgrading.');
} else {
$("#return_form2").submit(function(){//load the items
getItems();
});
}
});
var getItems = function() {
var timeLog, logLength, i;
i = 0;
logLength = localStorage.length-1; //how many items are in the database starting with zero
timeLog = '';
// loop through each item in the database
for (i = 0; i <= logLength; i++) {
var itemKey, value, values, firstname, password, email;
//variables for the key and values
itemKey = localStorage.key(i);
value = localStorage.getItem(itemKey);
values = JSON.parse(value);
firstname = values.fname;
password = values.pass;
email = values.email;
course = values.class;
var tt = course;
var un = document.return_form2.username.value;
var pw = document.return_form2.password.value;
var web = "Web Systems Development";
if ((un == firstname) && (pw == password) && (tt == web)){
window.location.href = "AppMenu.html";
return false;
}
else {
alert ("Incorrect Password");
}
}}
答案 0 :(得分:0)
我不确定((un == firstname) && (pw == password) && (tt == web))
是true
,无论如何,下一行为我工作
window.location="AppMenu.html";
此外,您不必返回false