我是一名新程序员,我对学习 JavaScript 非常感兴趣。我正在制作一个输入框,用户可以在其中输入金额。我希望将其保存到用户下次编辑/更新它为止,但我很难做到这一点。我在互联网上寻找它大约一个月了,但找不到太多我能理解的东西。我知道一种使用 Cookie 的方法,但我真的不知道如何编写 Cookie,我只需要一些提示和帮助来做到这一点。 谢谢。
HTML
<form id="update" onsubmit="return false" method="post">
<td><input class="rateContainer" value="Rate" disabled></td>
<td><input type="number" id="rate"></input></td>
<td><input type="submit" value ="Update" onclick="Update();" /></td>
</form>
JAVASCRIPT
function Update() {
var Update = document.getElementById("rate").submit;
}
最佳答案
查看本地存储:
window.onload=function(){
var input=document.getElementById("yourinputid");
if(localStorage.getItem("input")){
//if there is a stored value, apply it to the input
input.value=localStorage.getItem("input");
}
input.oninput=function(){
//if input is changed, store it
localStorage.setItem("input",input.value);
};
};
关于javascript - 尽管页面正在刷新,但仍保存输入值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41251733/