localStorage是HTML5提供的一种在客户端存储数据的机制,可以用来在浏览器中保存和读取键值对数据。使用localStorage设置多个<input>的方法如下:
<input type="text" id="input1">
<input type="text" id="input2">
<input type="text" id="input3">
var input1Value = document.getElementById("input1").value;
localStorage.setItem("input1Value", input1Value);
var input2Value = document.getElementById("input2").value;
localStorage.setItem("input2Value", input2Value);
var input3Value = document.getElementById("input3").value;
localStorage.setItem("input3Value", input3Value);
var input1Value = localStorage.getItem("input1Value");
document.getElementById("input1").value = input1Value;
var input2Value = localStorage.getItem("input2Value");
document.getElementById("input2").value = input2Value;
var input3Value = localStorage.getItem("input3Value");
document.getElementById("input3").value = input3Value;
localStorage.removeItem("input1Value");
使用localStorage设置多个<input>的优势是:
应用场景:
腾讯云相关产品和产品介绍链接地址:
领取专属 10元无门槛券
手把手带您无忧上云