将表格内容存储到HTML5本地存储中 [英] Storing table content to HTML5 local storage
本文介绍了将表格内容存储到HTML5本地存储中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,我在HTML中有多个输入框.然后,我用jquery创建一个表,然后单击一个按钮,将来自输入框的值存储到表中. 我不知道该怎么做是如何将这些值存储到本地存储中,以及页面重新加载的时间在表中显示它们.
So I have multiple input boxes in HTML. Then I create a table with jquery and on a click of a button I store values from the input boxes into my table. What I don't know how to do is how to store those values into local storage and the when the page reloads show them in the table.
这是我的代码,用于向表中添加新行:
This is my code for adding a new line to the table:
$().ready(function(){
$("#addLine").click(function(){
var chore = $("#chore").val();
var type= $("#type").val();
var importance = $("#importance").val();
counter++;
var newLine = "<tr><td>"+counter+"</td><td>"+chore+"</td>
<td>"+type+"</td><td>"+importance+"</td><td>"+date+"</td></tr>";
$("#tabela tbody").append(newLine);
});
});
推荐答案
使用
Use setItem
method of localStorage:
localStorage.setItem( "tabledata", $("#tabela").html() );
稍后您可以像这样获取它:
Later you can fetch it like this:
var tabledata = localStorage.getItem( "tabledata" );
$("#tabela").html( tabledata );
这篇关于将表格内容存储到HTML5本地存储中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文