我正在为我的工作场所制作一个网站,我需要将内容保留在访问该网站的所有计算机上
我有它的代码,我只需要让它留在网站上
<html>
<body>
<input type='text' id='idea' />
<input type='button' value='add to list' id='add' />
<br>
<ul id='list'></ul>
<script>
document.getElementById("add").onclick = function() {
//First things first, we need our text:
var text = document.getElementById("idea").value; //.value gets input values
//Now construct a quick list element
var li = "<li>" + text + " " + "<input type=checkbox>" + "Ready" + "</input>" + " " + "<input type=text>" + "</input>" + "</li>";
//Now use appendChild and add it to the list!
document.getElementById("list").innerHTML += li;
}
</script>
</body>
</html>
因此,如果有人能为我找到一个简单易行的解决方案,那就太棒了。 谢谢
最佳答案
可能是最简单的方法:您可以使用本地存储将数据存储在用户的机器上。但请记住 - 一旦用户清除其本地存储,数据就会被删除。
// Get stored text (undefined if nothing stored)
const storedIdea = localStorage.getItem("storedIdea");
// Store text
localStorage.setItem("storedIdea", text);
如果你想要更持久的东西,你必须使用身份验证和后端(你可以试试 Firebase!)。
关于javascript - 保存用户在网站上的输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57545663/