jquery-如何替换表列值
我是jQuery的新手。我有下表-jquery-如何替换表列值,jquery,jquery-ui,Jquery,Jquery Ui,我是jQuery的新手。我有下表- <table summary="This table lists all values in storage."> <caption>Values in storage</caption> <tbody> <tr> <th scope="row">JetBlue 983</th>
<table summary="This table lists all values in storage.">
<caption>Values in storage</caption>
<tbody>
<tr>
<th scope="row">JetBlue 983</th>
<td>Boston (BOS)</td>
<td>New York (JFK)</td>
</tr>
<tr>
<th scope="row">JetBlue 354</th>
<td>San Francisco (SFO)</td>
<td>Los Angeles (LAX)</td>
</tr>
<tr>
<th scope="row">JetBlue 465</th>
<td>New York (JFK)</td>
<td>Portland (PDX)</td>
</tr>
</tbody>
</table>
存储中的值
捷蓝983
波士顿(BOS)
纽约(肯尼迪)
捷蓝354
旧金山(SFO)
洛杉矶(洛杉矶)
捷蓝465
纽约(肯尼迪)
波特兰(PDX)
现在,我想在每次加载页面的该部分时,使用jquery读取本地存储并填充第二列中的值。最简单的方法是什么?您可以使用以下方法进行此操作 我假设您正在将json编码的数据保存到本地存储中
$(function{
var data = JSON.parse(localStorage.getItem('ITEM_KEY'));
// data is an object now
// find 2nd columns and populate
$('tr td:nth-child(2)').each(function(i){
$(this).text(data[i]);
});
})
假设要插入从localStorage找到的相同数据。数据数组中的元素数与列数相同
参考:及