本文介绍了如何从本地存储中检索数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经使用javascript创建了一个注册表单,数据存储在本地存储中,但我想从本地存储中检索数据以便登录,以下是我的controller.js -
I have created a register form using javascript from which data is getting stored in the local storage,but I want to retrieve data from local storage for login purpose, following is my controller.js-
//Storing data from local storage into an array of objects
var usersdata = JSON.parse( localStorage.getItem('key_users' ) );
function validatelogin()
{
usersdata = JSON.parse( localStorage.getItem('key_users' ) );
var usernameinput = document.getElementById("username");
var passwordinput = document.getElementById("password");
for(var p in userdata)
{
console.log(p+':'+userdata[p].username+'|'+userdata[p].email);
if(usernameinput==userdata[p].username && passwordinput==userdata[p].password)
{
alert("Logged in successfully");
}
}
}
尝试登录时,没有定义给出'userdata'的错误。请帮忙解决代码中的错误吗?
While trying to login, its giving error called 'userdata' is not defined..Please help with whats wrong in the code?
推荐答案
在<$ c里面$ c> for 循环更改 userdata
到 usersdata
这篇关于如何从本地存储中检索数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!