我有一個HTML表格,我正在使用jQuery添加和刪除行。當我添加例如10行,然後重新加載頁面時,所有添加的數據都將被刪除。保持頁面數據頁面刷新
如何在頁面重新加載後保留該數據?
這是我到目前爲止有:
function AddRow() {
$('.print-table').append("<tr><td>999</td><td><input type='text' name='id'></td><td><input type='text' name='id'></td><td><input type='text' name='id'></td><td><input type='text' name='id'></td><td><input type='text' name='id'></td><td><input type='text' name='id'></td><td>00</td><td><button class='btn btn-primary btn-xs removebtn' >Delete</button></td></tr>")
}
$('.print-table').on('click', '.removebtn', function() {
$(this).parent().parent().remove();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="table print-table">
<thead>
<tr class="danger">
<th width="30">S#</th>
<th width="100">VOUCHER#</th>
<th width="80">ID</th>
<th>FULL NAME OF STUDENT</th>
<th width="80">PAYABLE</th>
<th width="80">PAID</th>
<th width="100">PAID ON</th>
<th width="110">CLOSE-BAL</th>
<th width="80">ACTION</th>
</tr>
</thead>
<tbody>
<tr>
<td>999</td>
<td>
<input type="text" name="id" disabled="disabled">
</td>
<td>
<input type="text" name="id" disabled="disabled">
</td>
<td>
<input type="text" name="id" autofocus>
</td>
<td>
<input type="text" name="id" disabled="disabled">
</td>
<td>
<input type="text" name="id">
</td>
<td>
<input type="text" name="id" onfocusout="AddRow()">
</td>
<td>00</td>
<td>
<button class="btn btn-primary btn-xs removebtn">Delete</button>
</td>
</tr>
</tbody>
</table>
<button class="btn btn-primary xs" onclick="AddRow()">Add Row</button>
嘗試使用[Window.localStorage](https://developer.mozilla.org/en/docs/Web/API/Window/localStorage) –
相關:HTTP://計算器.com/q/22811160/104380 – vsync
這些(改變的)值應該是每個人都可見的,還是隻爲你?如果添加10行,並且其他人打開頁面,這10行也應該在那裏嗎? – DasSaffe