将一部分html保存到本地存储以后加载 [英] Save a part of html to local storage later load

查看:123
本文介绍了将一部分html保存到本地存储以后加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将html div(id = tabela)的内容保存到localstorage,以便可以通过localstorage将表的内容加载到另一个会话中。
如何将div内容转换为变量?

  var = tabelaContent; //<  - 我需要< div id = tabela>的内容在这
localStorage.setItem(tabelaContent,tabelaContent);

//然后,按下加载按钮

localStorage.getItem(tabelaContent);

如果还有其他方式让表格的内容持久化,请告诉我。



TIA。

解决方案

您可以使用 文档.getElementById(myID)。innerHTML ,如下所示:

  var = tabelaContent; 

tabelaContent = document.getElementById(tabela)。innerHTML
localStorage.setItem(tabelaContent,tabelaContent);


I need to save contents of a html div (id=tabela) to localstorage, so that the contents of the table can be loaded in another session via localstorage. How to get the div contents into a variable?

var = tabelaContent; //<-- I need contents of <div id=tabela> in this 
localStorage.setItem("tabelaContent",tabelaContent);

// then, upon pressing the "load" button

localStorage.getItem(tabelaContent);

FYI if there is another way of making the table's content persistent, let me know

TIA.

解决方案

You can use document.getElementById("myID").innerHTML, like this:

var = tabelaContent; 

tabelaContent = document.getElementById("tabela").innerHTML
localStorage.setItem("tabelaContent",tabelaContent);

这篇关于将一部分html保存到本地存储以后加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆