如何使用 HTML5 本地存储保存表单中的数据? [英] How to save data from a form with HTML5 Local Storage?
本文介绍了如何使用 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屋!
查看全文