动态添加内容到使用javascript保存的div

时间:2018-02-13 16:35:12

标签: javascript html dynamic

是否有动态添加内容到div甚至在关闭html页面后保存?
这样的东西但是一旦你关闭或刷新就会消失。
http://www.randomsnippets.com/2008/04/14/how-to-dynamically-add-content-to-a-div-via-javascript/

谢谢。

1 个答案:

答案 0 :(得分:0)

如果您希望数据在页面关闭后仍然存在,则应使用本地存储。

在这种情况下,数据将持续存在,直到用户明确清除缓存

// Store
localStorage.setItem("lastname", "Smith");
// Retrieve
document.getElementById("result").innerHTML = localStorage.getItem("lastname");

参考:https://www.w3schools.com/html/html5_webstorage.asp