所以我目前已将其存储在我的 localStorage 中:
{cart: "[{"Author":"Micheal Grant","title":"Gone"},{{"Author":"Micheal
Grant","title":"Fear"}]"
我只是想知道如何检索这些数据并将其显示在表格中:
例如:
<table border="1">
<tbody>
<tr>
<th> Book Title </th>
<th> Author </th>
</tr>
<tr>
<td class="Book_Title">Gone </td>
<td class="Author">Micheal Grant</td>
</tr>
<tr>
<td class="Book_Title">The Knife of never letting go</td>
<td class="Author">Ryan Howard</td>
</tr>
</tbody>
</table>
最佳答案
好的,这就是你应该做的
var cart= JSON.parse( localStorage.getItem('cart' ) );
$.each(cart, function(key, value){
$('tbody').append(`<tr>
<td class="Book_Title">${cart.title}</td>
<td class="Author">${cart.Author}</td>
</tr>`)
})
关于javascript - 在表中显示本地存储数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50312838/