javascript - 使用 Javascript 将数据存储到本地存储

标签 javascript local-storage

如何将原始密码存储到我的本地存储?

我有两个输入用户名和密码:

<input id="myInput" type="text" name="myInput" placeholder="Input">
<input id="myPW" type="password" name="myPassword" placeholder="Password">

我想在我的 javascript 中做的是存储我的用户名、转换为 Base64 的密码以及密码的原始数据。但它只存储用户名和 Base64 密码。原始密码不会被存储。我该如何修复它?

最佳答案

因为在使用它推送原始密码之前,您将 inpw.value 设置为空字符串。

  userArray.push(inp.value);
  localStorage.setItem('user', JSON.stringify(userArray));
  inp.value = "";

  passArray.push(window.btoa(inpw.value));
  localStorage.setItem('pass', JSON.stringify(passArray));
  inpw.value = ""; // This makes next inpw.value equals ""

  origPassArray.push(inpw.value); // So this will push an empty string to the array
  localStorage.setItem('orig', JSON.stringify(origPassArray));
  inpw.value = "";

关于javascript - 使用 Javascript 将数据存储到本地存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54920213/

相关文章:

javascript - 我想使用 Jquery 在我的网站中嵌入 API 调用

javascript - 从 localStorage 存储和检索 Set

javascript - 使用 angularJS 从本地存储过滤数据

windows-mobile - 适用于 Windows Mobile 6 的支持 HTML5 的浏览器

iphone - iPhone Safari 上的 HTML5 - localStorage 存储的数据并不总是持久存在。为什么?

javascript - 如何知道异步函数调用何时完成(Javascript)

javascript - 是否可以创建一个强加 Angular 过滤器的 css 类?

javascript - 错误node.js无法加载资源

javascript - 对 JSON 数组进行排序并使用 $.each 进行回显

javascript - 如何将 localStorage 从 JS 发送到 PHP 文件(?)