[英]Saving user input to local storage
I have the code to save user input for a single input box here and i would like to have it save multiple user inputs.我有在这里保存单个输入框的用户输入的代码,我希望它保存多个用户输入。 I have asked people and they have told me to do things i dont fully understand, could someone rewrite this for me to where i can have multiple ids?
我问过人们,他们告诉我做我不完全理解的事情,有人可以为我重写这个,让我可以有多个 id 吗? Id rather not right this 20+ times for each individual id.
对于每个单独的 id,这 20 多次 Id 是不对的。 Thanks!
谢谢!
var storedItem = localStorage.getItem("name")
function save(){
var Item = document.getElementById("name").value;
localStorage.setItem("name", Item);
}
function get(){
document.getElementById('name').value = localStorage.getItem('name');
}
You can just pass the id of the field to the function and save/get it that way您可以将字段的 id 传递给函数并以这种方式保存/获取它
function save(id) {
var Item = document.getElementById(id).value;
localStorage.setItem(id, Item);
}
function get(id) {
document.getElementById(id).value = localStorage.getItem(id);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.