如何使用HTML5本地存储从表单保存数据? [英] How to save data from a form with HTML5 Local Storage?

查看:605
本文介绍了如何使用HTML5本地存储从表单保存数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,可以登录到一个网站,但不在我的网站,我希望他们能够通过HTML5本地存储将表单数据保存在我的网站中。但不是如何。任何想法?我的表单是这样的:

I have a form that makes logging into a website but not in mine and I want them to be saved form data in my web with HTML5 local storage. But not how. Any idea? My form is this:

<form action="http://issuefy.ca.vu/on/login.php" class="form-login"  method="post" /> 
<input name="email" type="email" id="email" required="" placeholder="Email" />
<input name="password" type="password" required="" placeholder="Contraseña" />
</form>


推荐答案

LocalStorage有一个setItem方法。您可以像这样使用它:

LocalStorage has a setItem method. You can use it like this:

var inputEmail= document.getElementById("email");
localStorage.setItem("email", inputEmail.value);

当您想要取得该值时,您可以执行以下操作:

When you want to get the value, you can do the following:

var storedValue = localStorage.getItem("email");

也可以在按钮点击时存储这些值,如下所示:

It is also possible to store the values on button click, like so:

<button onclick="store()" type="button">StoreEmail</button>

<script  type="text/javascript">
  function store(){
     var inputEmail= document.getElementById("email");
     localStorage.setItem("email", inputEmail.value);
    }
</script>

这篇关于如何使用HTML5本地存储从表单保存数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆