Как сохранить данные таблицы в local storage?
Нужно сохранить данные таблицы в localstorage, чтобы после перезагрузки введенные данные погружались оттуда. HTML
function create_tr(table_id) {
let table_body = document.getElementById(table_id),
first_tr = table_body.firstElementChild,
tr_clone = first_tr.cloneNode(true);
table_body.append(tr_clone);
clean_first_tr(table_body.firstElementChild);
}
function clean_first_tr(firstTr) {
let children = firstTr.children;
children = Array.isArray(children) ? children : Object.values(children);
children.forEach(x=>{
if(x !== firstTr.lastElementChild) {
x.firstElementChild.value = '';
}
});
}
function remove_tr(This) {
if(This.closest('tbody').childElementCount == 1)
{
alert("You Don't have Permission to Delete This ?");
}else{
This.closest('tr').remove();
}
}
HTML
<div class="container">
<table class="_table">
<thead>
<tr>
<th>Название лекарства</th>
<th>Кратность приёма</th>
<th>Время приёма</th>
<th width="50px">
<div class="action_container">
<button class="success"
onclick="create_tr('table_body')">
<i class="fa fa-plus"></i>
</button>
</div>
</th>
</tr>
</thead>
<tbody id="table_body">
<tr>
<td>
<input type="text" class="form_control" id="name"
placeholder="Парлазин">
</td>
<td>
<input type="text" class="form_control" id="taking"
placeholder="1 таблетка 2 раза в день">
</td>
<td>
<textarea class="form_control" id="time"
placeholder="Утром и вечером"></textarea>
</td>
<td>
<div class="action_container">
<button class="danger" onclick="remove_tr(this)">
<i class="fa fa-close"></i>
</button>
</div>
</td>
</tr>
</tbody>
</table>
</div>