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

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

问题描述

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

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.

推荐答案

你可以使用document.getElementById("myID").innerHTML,像这样:>

var = tabelaContent; 

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

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

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