如何使用localStorage存儲我的應用程序的登錄憑據?我想它會在我退出應用程序時將它存儲在某個地方,然後當我再次打開應用程序時,這些字段將預先填入localStorage的信息。這是我的代碼到目前爲止。phonegate的localStorage將在退出應用程序後存儲內容?
function onDeviceReady() {
alert("ready");
var email = window.localStorage.getItem("email");
var password = window.localStorage.getItem("password");
document.getElementById("email").value = email;
document.getElementById("password").value = password;
}
//If checkbox gets checked then save credentials, if unchecked then forget
function rememberMe() {
if(document.getElementById('remember_me').checked) {
alert("checked");
window.localStorage.setItem("email", document.getElementById("email").value);
window.localStorage.setItem("password", docuement.getElementById("password").value);
}
else {
alert("unchecked");
window.localstorage.clear();
}
}
代碼無法正常工作? –
不,在我退出並再次打開應用程序後,字段未預先填充來自localStorage的信息。 – romeo
代碼似乎正在運行,嘗試在桌面瀏覽器中測試並調試執行,可能是流程不正確。 –