我正在尝试使用jquery将新数据(来自JSON)添加到现有表中。
例如,在我的html中,我有这个表:
<table data-role="table" data-mode="columntoggle" class="ui-responsive" data-column-btn-text="Filter Columns" id="MyTable">
<thead>
<tr>
<th data-priority="1">A</th>
<th data-priority="2">B</th>
<th data-priority="3">C</th>
</tr>
</thead>
<tbody>
<tr>
<td>a1</td>
<td>b1</td>
<td>c1</td>
</tr>
</tbody>
</table>
我正在尝试使用以下方法(用于从JSON添加新数据):
var response = [{
"A":"a2",
"B":"b2",
"C":"c2"
},
{
"A":"a3",
"B":"b3",
"C":"c3"
},
{
"A":"a4",
"B":"b4",
"C":"c4"
}];
$.each(response, function(i, item) {
$('<tr>').html(
//"<tr>" +
"<td>" + response[i].A + "</td><td>" + response[i].B + "</td><td>" + response[i].C + "</td>" + "</tr>").appendTo('#MyTable');
});
为什么它不能工作?
#MyTable
中,这些新元素将不会在tbody
或thead
元素中? - DontVoteMeDownitem.A
代替response[i].A
。 - MD. Sahib Bin Mahboob